I'm working on a project and want to open the window to the position the same as last time the window was closed, and open the window the same size as last time was closed also. The rough script is as below:
When user open the window and resize it, and then close the window, next time open it again, I want the window to be opened the position which was last closed, and size the same as last time closed.
public class BrowserGUI extends Shell{
protected static int winX = 0; //X position of the window
protected static int winY = 0; //Y position of the window
protected static int winWidth = 800; //Window width
protected static int winHeight = 600; //Window height
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
new BrowserGUI();
Rectangle rect = display.getBounds();
int screenWidth = rect.width;
int screenHeight = rect.height;
winX = (screenWidth-winWidth)/2;
winY = (screenHeight-winHeight)/2;
shell.setBounds(winX, winY, winWidth, winHeight);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
public void finalize(){
Rectangle rect = this.getShell().getBounds();
winWidth = rect.width;
winHeight = rect.height;
}
}