/**
* Setup window is located in the middle of screen
* @param the Shell to adjust the position of the Window object
*/
public static void Center (shell shell)
{
Get screen height and width
int screenh = Toolkit.getdefaulttoolkit (). Getscreensize (). Height;
int screenw = Toolkit.getdefaulttoolkit (). Getscreensize (). width;
Get Object window height and width
int shellh = Shell.getbounds (). Height;
int shellw = Shell.getbounds (). width;
If the object window is taller than the screen height, force it to
if (Shellh > Screenh)
SHELLH = screenh;
If the object window is wider than the width of the screen, force it to
if (Shellw > Screenw)
SHELLW = Screenw;
Anchor Object window coordinates
Shell.setlocation (((SCREENW-SHELLW)/2), (((SCREENH-SHELLH)/2));
}
/**
* Setup window is located in the middle of screen
* @param display device
* @param the Shell to adjust the position of the Window object
*/
public static void Center (display display, shell shell)
{
Rectangle bounds = Display.getprimarymonitor (). getbounds ();
Rectangle rect = Shell.getbounds ();
int x = bounds.x + (bounds.width-rect.width)/2;
int y = bounds.y + (bounds.height-rect.height)/2;
Shell.setlocation (x, y);
}
SWT Shell Setup window in the middle of the screen