List of usage examples for java.awt Window getSize
public Dimension getSize()
From source file:Main.java
/** * Locates a dimension on the screen being the left space the width factor of difference between the screen size and * the dimension. A value of 0 moves the dimension to the left, while a value of 1 moves the dimension to the right. * The same applies to the height.// w w w. jav a 2s. co m * * @param window The window. * @param factorWidth Width factor. * @param factorHeight Height factor. * @return The top-left corner point. */ public static Point moveWindowOnScreen(Window window, double factorWidth, double factorHeight) { Dimension sz = window.getSize(); Dimension szScreen = getScreenSize(window); Point pt = getScreenPosition(window); if (szScreen.width > sz.width) { pt.x = pt.x + (int) ((szScreen.width - sz.width) * factorWidth); pt.y = pt.y + (int) ((szScreen.height - sz.height) * factorHeight); } return pt; }
From source file:Main.java
/** * Centers the given window on the primary screen. * * @param window//from www . j a v a2s. co m * The window to center */ public static void center(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension windowSize = window.getSize(); window.setLocation((screenSize.width - windowSize.width) / 2, (screenSize.height - windowSize.height) / 2); }
From source file:Main.java
public static void setWindowLocationRelativeTo(Window window, Window relativeWindow) { Rectangle windowBounds = window.getBounds(); Dimension rwSize = relativeWindow.getSize(); Point rwLoc = relativeWindow.getLocation(); int dx = rwLoc.x + ((rwSize.width - windowBounds.width) >> 1); int dy = rwLoc.y + ((rwSize.height - windowBounds.height) >> 1); Dimension ss = window.getToolkit().getScreenSize(); if (dy + windowBounds.height > ss.height) { dy = ss.height - windowBounds.height; dx = rwLoc.x < (ss.width >> 1) ? rwLoc.x + rwSize.width : rwLoc.x - windowBounds.width; }//from w w w. ja v a2 s.com if (dx + windowBounds.width > ss.width) { dx = ss.width - windowBounds.width; } if (dx < 0) { dx = 0; } if (dy < 0) { dy = 0; } window.setLocation(dx, dy); }
From source file:Main.java
public static void centerFrame(Window frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = frame.getSize(); screenSize.height = screenSize.height / 2; screenSize.width = screenSize.width / 2; size.height = size.height / 2;//from w ww. j a v a 2s . co m size.width = size.width / 2; int y = screenSize.height - size.height; int x = screenSize.width - size.width; frame.setLocation(x, y); }
From source file:Main.java
/** * Centers the given window over its owner window. * * @param window/*from w ww.j a v a2 s. c o m*/ * The window to center * @param ownerWindow * The window to center the other window over */ public static void center(Window window, Window ownerWindow) { Point ownerWindowLocation = ownerWindow.getLocation(); Dimension ownerWindowDimension = ownerWindow.getSize(); Dimension windowSize = window.getSize(); window.setLocation(ownerWindowLocation.x + (ownerWindowDimension.width - windowSize.width) / 2, ownerWindowLocation.y + (ownerWindowDimension.height - windowSize.height) / 2); }
From source file:Main.java
public static void center(Window frame, int left, int right, int top, int bottom) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > (screenSize.height - top - bottom)) { frameSize.height = screenSize.height - top - bottom; }/* w w w. j av a2 s. co m*/ if (frameSize.width > screenSize.width - left - right) { frameSize.width = screenSize.width - left - right; } if (!frameSize.equals(frame.getSize())) { frame.setSize(frameSize); } frame.setLocation(left + (screenSize.width - frameSize.width) / 2, top + (screenSize.height - frameSize.height) / 2); }
From source file:Main.java
/** * This method returns the point at which the incoming dialog will be * perfectly centered on screen.// w w w .j a v a2 s . c om * @param windowToCenter The window to center. Make sure thesize has been set (pack or validate first). * @return The point to set on the dialog using setLocation(). */ public static Point getCenteredWindowPoint(java.awt.Window windowToCenter) { //Center the Dialog Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = windowToCenter.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } Point centerCoord = new Point((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); return centerCoord; }
From source file:Main.java
/** * Centers a window within a specified space. If the window is larger than * the width/height of the space, it may optionally overflow: its X and Y * will be less than those passed. However, it is not allowed to overflow * to negative coordinates.// w w w. ja v a 2 s .c om */ private static void center(Window window, Rectangle bounds, boolean allowOverflow) { Dimension windowSize = window.getSize(); int offsetX = (bounds.width - windowSize.width) / 2; if ((offsetX < 0) && !allowOverflow) { offsetX = 0; } int x = bounds.x + offsetX; if (x < 0) { x = 0; } int offsetY = (bounds.height - windowSize.height) / 2; if ((offsetY < 0) && !allowOverflow) { offsetY = 0; } int y = bounds.y + offsetY; if (y < 0) { y = 0; } window.setLocation(x, y); }
From source file:Splash.java
/** Centre a Window, Frame, JFrame, Dialog, etc. */ public static void centre(Window w) { // After packing a Frame or Dialog, centre it on the screen. Dimension us = w.getSize(), them = Toolkit.getDefaultToolkit().getScreenSize(); int newX = (them.width - us.width) / 2; int newY = (them.height - us.height) / 2; w.setLocation(newX, newY);/* w ww. j a v a2s . co m*/ }
From source file:Main.java
/** * Move the specified window to the center of the screen. Cautious, it may * occupy two different screens if the system has two or more combined * screens.//w w w .j a v a2 s .com * * @param window * the specified window */ public static void setWindowToScreenCenter(Window window) { int screenWidth = window.getToolkit().getScreenSize().width; int screenHeight = window.getToolkit().getScreenSize().height; window.setLocation(screenWidth / 2 - window.getSize().width / 2, screenHeight / 2 - window.getSize().height / 2); }