List of usage examples for java.awt Window getSize
public Dimension getSize()
From source file:Main.java
/** GUI utility (set frame on the center of screen) */ public static void setCenter(Window w) { Dimension scSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension wndSize = w.getSize(); w.setLocation((scSize.width - wndSize.width) / 2, (scSize.height - wndSize.height) / 2); }
From source file:Main.java
/** * gets the center point for "what" relative to the given Dimension dim * @param dim//from ww w. ja v a 2s . com * @param what */ private static Point center(java.awt.Dimension dim, java.awt.Window what) { // Determine the new location of the window int w = what.getSize().width; int h = what.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; return new Point(x, y); }
From source file:Main.java
/** * Gets the window actual size.//from ww w.jav a 2 s . com * * @param window * the window * @return the window actual size */ public static Dimension getWindowActualSize(final Window window) { if (window.isVisible()) { return window.getSize(); } if (window instanceof Frame) { final Frame frame = (Frame) window; if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) { return Toolkit.getDefaultToolkit().getScreenSize(); } } return window.getSize(); }
From source file:Main.java
/** * Enlarges a window to its preferred width and/or height if it is too small. *///from ww w. j a va 2 s. co m public static void repack(final Window w) { final Dimension size = getRepackSize(w); if (!w.getSize().equals(size)) w.setSize(size); }
From source file:Main.java
public static void centerOnScreen(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = window.getSize(); window.setLocation((screenSize.width - size.width) / 2, (screenSize.height - size.height) / 2); }
From source file:Main.java
public static GraphicsDevice getCurrentScreen(Window window) { return getCurrentScreen(window.getLocation(), window.getSize()); }
From source file:Main.java
public static void centerContainer(Window window) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = window.getSize(); int newWidth = (screen.width - size.width) / 2; int newHeight = (screen.height - size.height) / 2; window.setLocation(newWidth, newHeight); }
From source file:Main.java
public static void center(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = window.getSize(); frameSize.height = ((frameSize.height > screenSize.height) ? screenSize.height : frameSize.height); frameSize.width = ((frameSize.width > screenSize.width) ? screenSize.width : frameSize.width); window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); }
From source file:Splash.java
/** Maximize a window, the hard way. */ public static void maximize(Window w) { Dimension us = w.getSize(), them = Toolkit.getDefaultToolkit().getScreenSize(); w.setBounds(0, 0, them.width, them.height); }
From source file:Main.java
public static void setToScreenCenter(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension windowSize = window.getSize(); if (windowSize.height > screenSize.height) { windowSize.height = screenSize.height; }//w ww . ja v a 2 s.c o m if (windowSize.width > screenSize.width) { windowSize.width = screenSize.width; } window.setLocation((screenSize.width - windowSize.width) / 2, (screenSize.height - windowSize.height) / 2); }