Wednesday, September 9, 2009

Disabling close button in SWT shell window

Below snippet of code can be used in a SWT dialog box to disable the close button on window.

//disabling the close button
dialogShell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
e.doit = false;

Center a SWT Shell on the screen

Below snippet of code can be used to center a SWT shell on the screen

//center the dialog screen to the monitor
Monitor primary = display.getPrimaryMonitor ();
Rectangle bounds = primary.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);;

Below link will provide a brief idea about creating a splash screen using SWT