swt

Mattepuffo's logo
Centrare una finestra in SWT

Centrare una finestra in SWT

SWT è la libreria standard per le GUI usata da Eclipse (al contrario di Netbeans che usa SWING).

Oggi ho cominciato ad usarla e vi posto subito un articolo su come centrare le finestre.

Una volta creato un progetto SWT create una ApplicationWindow; vi ritroverete con una cosa del genere:


import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainFrame {

public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setSize(450, 200);
shell.setText("SWT Application");
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}

Vediamo come fare per centrare la finestra al centro dello schermo.