blob: edc16cef94773c1536ce4d33abbda22499276a99 (
plain) (
blame)
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
|
package util;
import java.awt.Window;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
public abstract class GuiOrganizer {
/* receive GUI, set it to center of the screen */
public static void centerGUI(Window gui) {
Display display = new Display();
// detect bounds of primary display.
Rectangle rect = display.getPrimaryMonitor().getBounds();
// without this, we get an expection, not sure what this does though :)
display.dispose();
double width = rect.width;
double height = rect.height;
double xPosition = (width / 2 - gui.getWidth() / 2);
double yPosition = (height / 2 - gui.getHeight() / 2);
gui.setLocation((int) xPosition, (int) yPosition);
}
}
|