1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public class SWTUtils {
public static void show(Shell shell) {
Display display = shell.getDisplay();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
public static void sizeToMonitor(Shell shell) {
sizeToMonitor(shell, shell.getMonitor());
}
public static void sizeToMonitor(Shell shell, Monitor monitor) {
Rectangle area = monitor.getClientArea();
shell.setBounds(area);
}
public static void center(Shell shell, double fw, double fh) {
Rectangle area = shell.getMonitor().getClientArea();
int width = (int) (area.width*fw);
int height = (int) (area.height*fh);
int x = area.x + (area.width - width)/2;
int y = area.y + (area.height - height)/2;
shell.setBounds(x, y, width, height);
}
public static void sizeToScreen(Shell shell) {
sizeToScreen(shell, shell.getMonitor());
}
public static void sizeToScreen(Shell shell, Monitor monitor) {
Rectangle size = monitor.getBounds();
shell.setBounds(size);
}
} |
Partager