[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Centering a Dialog on Screen

Child Shell(s) automatically position themselves exactly centered in the parent Shell (which is usually the desired behavior).  To manually center any Shell, use the following snippet:

[code]
int width = display.getClientArea().width;
int height = display.getClientArea().height;
shell.setLocation(((width - shell.getSize().x) / 2) + display.getClientArea().x, ((height - shell.getSize().y) / 2) + display.getClientArea().y);
[/code]

Assuming 'shell' is the local field representing your Shell and 'display' is the local field representing shell.getDisplay(), shell will be perfectly centered on the screen agnostic of platform and screen trim (e.g. Linux panels or PocketPC menubars).