List of usage examples for java.awt Window getWidth
public int getWidth()
From source file:Main.java
public static void centralizeWindow(Window window) { int windowWidth = window.getWidth(); int windowHeight = window.getHeight(); int screenWidth = (int) java.awt.Toolkit.getDefaultToolkit().getScreenSize().getWidth(); int screenHeight = (int) java.awt.Toolkit.getDefaultToolkit().getScreenSize().getHeight(); window.setBounds(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2, windowWidth, windowHeight);//from w ww . j av a 2s . c o m }
From source file:Main.java
private static void centerWindow(Window w, Point center) { int x = center.x - w.getWidth() / 2; int y = center.y - w.getHeight() / 2; w.setLocation(x, y);//from w ww. ja v a 2 s . c o m }
From source file:Main.java
/** * Centers a {@link Window} at the center of the screen.<br/> * Windows like {@link JDialog} and {@link JFrame} (and others) that extend from {@link Window} applies for this method. * //from ww w . java2s . c o m * @param window */ public static void centerWindow(Window window) { window.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width) / 2 - window.getWidth() / 2, (Toolkit.getDefaultToolkit().getScreenSize().height) / 2 - window.getHeight() / 2); }
From source file:Main.java
/** * This method packs, sets the size, and sets the position of the window given * * @param window/*from w w w . j a v a 2 s. co m*/ */ public static void centerAndPack(Window window) { window.pack(); int x = getWindowXCenter() - (window.getWidth() / 2); int y = getWindowYCenter() - (window.getHeight() / 2); window.setLocation(x, y); window.setMinimumSize(new Dimension(window.getWidth(), window.getHeight())); }
From source file:Main.java
/** * * @deprecated Use automatic RitDialog centering facilities *///from w w w. j a v a 2s .c om public static void centerWindowOnScreen(Window window) { Dimension dim = window.getToolkit().getScreenSize(); window.setLocation((dim.width - window.getWidth()) / 2, (dim.height - (window.getHeight())) / 2); }
From source file:Main.java
public static void centerWindow(Window w, Window reference) { Point refCorner = reference.getLocation(); Point center = new Point(refCorner.x + reference.getWidth() / 2, refCorner.y + reference.getHeight() / 2); centerWindow(w, center);/*from w w w . j a va2 s. c om*/ }
From source file:Main.java
/** * Centers a given window on the screen. * //from w w w . j a v a 2 s.c o m * @param window * The window, frame or dialog */ public static void centerOnScreen(Window window) { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((d.getWidth() - window.getWidth()) / 2); int y = (int) ((d.getHeight() - window.getHeight()) / 2); window.setLocation(x, y); }
From source file:Main.java
public static void center(Window window) { Dimension screen = window.getToolkit().getScreenSize(); window.setLocation((screen.width - window.getWidth()) / 2, (screen.height - window.getHeight()) / 2); }
From source file:Main.java
public static void center(Window window) { window.pack();//from w w w. j a v a 2 s . c o m Rectangle bounds = window.getGraphicsConfiguration().getBounds(); int width = window.getWidth(); int height = window.getHeight(); int centerX = bounds.x + bounds.width / 2; int centerY = bounds.y + bounds.height / 2; window.setLocation(centerX - width / 2, centerY - height / 2); window.setPreferredSize(new Dimension(width, height)); }
From source file:Main.java
/** * {@link Window#pack() Packs} the given window and positions it so that its * center stays the same./*from ww w . j a v a2s . c o m*/ * * @param window * The window to pack and recenter */ public static void repackCentered(Window window) { Point center = getCenter(window.getBounds()); window.pack(); window.setLocation((center.x - window.getWidth() / 2), (center.y - window.getHeight() / 2)); window.repaint(); }