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); } }