How to Move a Window the Center of Screen in Eclipse Rcp
Using eclipse-rcp HelloWorld Example To be able to do this we need to override the WorkbenchWindowAdvisor's postWindowCreate method in...
https://www.czetsuyatech.com/2021/07/java-eclipse-rcp-move-window-to-center.html
Using eclipse-rcp HelloWorld Example
To be able to do this we need to override the WorkbenchWindowAdvisor's postWindowCreate method in the ApplicationWorkbenchWindowAdvisor class.
To be able to do this we need to override the WorkbenchWindowAdvisor's postWindowCreate method in the ApplicationWorkbenchWindowAdvisor class.
@Override /** * ostWindowCreate - called after the window has been created, either from an * initial state or from a restored state; used to adjust the window */ public void postWindowCreate() { super.postWindowCreate(); //get the workbench window IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); Display display = configurer.getWindow().getWorkbench().getDisplay(); //get the desktop window Shell shell = configurer.getWindow().getShell(); Rectangle rectBounds = display.getBounds(); int minWidth = 600; int minHeight = 400; int x = 400; int y = 100; //note: for multi-monitors negative x value is returned if(rectBounds.x > 0) { //single monitor // This formulae calculate the shell's Left ant Top x = (rectBounds.width - minWidth) / 2; y = (rectBounds.height - minHeight) / 2; } else { //assumption 2 monitors that's why rectBounds.width is divided by 2 x = (rectBounds.width / 2 - minWidth) / 2; y = (rectBounds.height - minHeight) / 2; } // based on the above calculations, set the window location shell.setBounds(x, y, minWidth, minHeight); }
Post a Comment