SWT Shell Setup window in the middle of the screen

Source: Internet
Author: User

/**
* 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.