List of usage examples for java.awt Window getSize
public Dimension getSize()
From source file:Main.java
/** * // w w w .j a v a 2s . c o m * @return The middle point on the screen, for the window */ public static Point getCenterPoint(Window window) { // Get the size of the screen Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); // Determine the new location of the window int w = window.getSize().width; int h = window.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; return new Point(x, y); }
From source file:Main.java
public static void centerWindowOnScreen(Window aWindow) { Rectangle bounds = getScreenBounds(aWindow); Point p = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); Dimension windowSize = aWindow.getSize(); p.x -= windowSize.width / 2;/*from w w w .j a v a2 s . c o m*/ p.y -= windowSize.height / 2; aWindow.setLocation(p); }
From source file:Win.java
public static void position(Window frame, Component ref, double xfrac, double yfrac) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = frame.getSize(); Dimension refSize = (ref != null) ? ref.getSize() : screenSize; Point origin = (ref != null) ? ref.getLocationOnScreen() : new Point(0, 0); int x = origin.x + relativePoint(xfrac, refSize.width, size.width); int y = origin.y + relativePoint(yfrac, refSize.height, size.height); // make sure frame is entirely on screen x = Math.max(0, Math.min(screenSize.width - size.width, x)); y = Math.max(0, Math.min(screenSize.height - size.height, y)); frame.setLocation(x, y);//from w w w . j av a 2 s. c o m }
From source file:Main.java
/** * Centers the Frame on the screen//www . ja va 2 s . c o m */ public static void center(java.awt.Window frame) { // Get the size of the screen java.awt.Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); // Determine the new location of the window int w = frame.getSize().width; int h = frame.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; // Move the window frame.setLocation(x, y); }
From source file:Main.java
public static void centerInParent(Window window, Component myParent) { int x;//from w ww . ja v a 2s . c om int y; Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = window.getSize(); if (parentSize.width > mySize.width) x = ((parentSize.width - mySize.width) / 2) + topLeft.x; else x = topLeft.x; if (parentSize.height > mySize.height) y = ((parentSize.height - mySize.height) / 2) + topLeft.y; else y = topLeft.y; window.setLocation(x, y); }
From source file:Main.java
/** * Positions the specified frame at a relative position in the screen, where 50% is considered to be the center of the * screen./*from w w w. j a va 2 s . c o m*/ * * @param frame the frame. * @param horizontalPercent the relative horizontal position of the frame (0.0 to 1.0, where 0.5 is the center of the * screen). * @param verticalPercent the relative vertical position of the frame (0.0 to 1.0, where 0.5 is the center of the * screen). */ public static void positionFrameOnScreen(final Window frame, final double horizontalPercent, final double verticalPercent) { final Rectangle s = frame.getGraphicsConfiguration().getBounds(); final Dimension f = frame.getSize(); final int spaceOnX = Math.max(s.width - f.width, 0); final int spaceOnY = Math.max(s.height - f.height, 0); final int x = (int) (horizontalPercent * spaceOnX) + s.x; final int y = (int) (verticalPercent * spaceOnY) + s.y; frame.setBounds(x, y, f.width, f.height); frame.setBounds(s.intersection(frame.getBounds())); }
From source file:Main.java
public static void centerOnScreen(Window w, Window parent) { Rectangle r = new Rectangle(); if (parent == null) { r.setSize(Toolkit.getDefaultToolkit().getScreenSize()); } else {/*from w ww . j a v a2 s . co m*/ r.setLocation(parent.getLocation()); r.setSize(parent.getSize()); } // Determine the new location of the alert int x = r.x + (r.width - w.getWidth()) / 2; int y = r.y + (r.height - w.getHeight()) / 2; // Move the alert w.setLocation(x, y); }
From source file:Main.java
public static void centerWithinScreen(final Window wind) { if (wind == null) { return;/*from w w w.j a v a2 s. c o m*/ } final Toolkit toolKit = Toolkit.getDefaultToolkit(); final Rectangle rcScreen = new Rectangle(toolKit.getScreenSize()); final Dimension windSize = wind.getSize(); final Dimension parentSize = new Dimension(rcScreen.width, rcScreen.height); if (windSize.height > parentSize.height) { windSize.height = parentSize.height; } if (windSize.width > parentSize.width) { windSize.width = parentSize.width; } center(wind, rcScreen); }
From source file:Main.java
/** * Positions the specified frame at a relative position in the screen, where * 50% is considered to be the center of the screen. * // w w w.ja v a 2 s .com * @param frame * the frame. * @param horizontalPercent * the relative horizontal position of the frame (0.0 to 1.0, where * 0.5 is the center of the screen). * @param verticalPercent * the relative vertical position of the frame (0.0 to 1.0, where 0.5 * is the center of the screen). */ public static void positionFrameOnScreen(final Window frame, final double horizontalPercent, final double verticalPercent) { final Rectangle s = getMaximumWindowBounds(); final Dimension f = frame.getSize(); final int w = Math.max(s.width - f.width, 0); final int h = Math.max(s.height - f.height, 0); final int x = (int) (horizontalPercent * w) + s.x; final int y = (int) (verticalPercent * h) + s.y; frame.setBounds(x, y, f.width, f.height); }
From source file:Main.java
/** * Positions the specified frame at a relative position in the screen, where 50% is considered * to be the center of the screen./* w w w . j a v a 2s .c o m*/ * * @param frame the frame. * @param horizontalPercent the relative horizontal position of the frame (0.0 to 1.0, * where 0.5 is the center of the screen). * @param verticalPercent the relative vertical position of the frame (0.0 to 1.0, where * 0.5 is the center of the screen). */ public static void positionFrameOnScreen(final Window frame, final double horizontalPercent, final double verticalPercent) { final Rectangle s = frame.getGraphicsConfiguration().getBounds(); final Dimension f = frame.getSize(); final int w = Math.max(s.width - f.width, 0); final int h = Math.max(s.height - f.height, 0); final int x = (int) (horizontalPercent * w) + s.x; final int y = (int) (verticalPercent * h) + s.y; frame.setBounds(x, y, f.width, f.height); }