List of usage examples for java.awt Window getToolkit
public Toolkit getToolkit()
From source file:Main.java
public static void closeWindow(Window w) { w.getToolkit().getSystemEventQueue().postEvent(new WindowEvent(w, WindowEvent.WINDOW_CLOSING)); }
From source file:Main.java
/** * * @deprecated Use automatic RitDialog centering facilities *//*w w w . j a va2s.c o m*/ 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
/** * 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.//from w w w . ja v a 2 s. c om * * @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); }
From source file:Main.java
public static void centerWindowOnScreen(Window window) { int screenHeight = (int) window.getToolkit().getScreenSize().getHeight(); int screenWidth = (int) window.getToolkit().getScreenSize().getWidth(); int x = (screenWidth - window.getWidth()) / 2; int y = (screenHeight - window.getHeight()) / 2; window.setLocation(x, y);/*from w ww .jav a2 s .co m*/ }
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
/** * Zentriert ein Window relativ zu dem Parent-Window * /*from ww w . j a v a 2s . c om*/ * @param parent * Parent-Window, wenn null, dann wird relativ zu dem Bildschirm * zentriert * @param child * Window das zentrirt werden soll. */ static public void centreWindow(Window parent, Window child) { if (child == null) return; Point parentLocation = null; Dimension parentSize = null; if (parent == null) { parentLocation = new Point(0, 0); parentSize = child.getToolkit().getScreenSize(); } else { parentLocation = parent.getLocationOnScreen(); parentSize = parent.getSize(); } Dimension childSize = child.getSize(); child.setLocation((int) (parentLocation.getX() + parentSize.getWidth() / 2 - childSize.getWidth() / 2), (int) (parentLocation.getY() + parentSize.getHeight() / 2 - childSize.getHeight() / 2)); }
From source file:Main.java
public static Insets getScreenInsets(Window win) { Insets si;//from ww w.java2 s .co m if (win == null) { si = Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getDefaultConfiguration()); } else { si = win.getToolkit().getScreenInsets(win.getGraphicsConfiguration()); } return si; }
From source file:Main.java
/** * Center the given window within the screen boundaries. * * @param window the window to be centered. *//*from w ww . j av a 2s. c o m*/ public static void centerWindow(Window window) { Rectangle bounds; try { bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); } catch (Throwable t) { Toolkit tk = window.getToolkit(); Dimension ss = tk.getScreenSize(); bounds = new Rectangle(ss); } int width = window.getWidth(), height = window.getHeight(); window.setBounds(bounds.x + (bounds.width - width) / 2, bounds.y + (bounds.height - height) / 2, width, height); }
From source file:AWTUtilities.java
/** * Reposition the specified window so that it necessarily fits on the screen, * while trying to minimize changes.// ww w. ja v a 2 s . c om */ public static void forceToScreen(Window window) { Dimension screenSize = window.getToolkit().getScreenSize(); Rectangle bounds = window.getBounds(); bounds.width = Math.min(bounds.width, screenSize.width); bounds.height = Math.min(bounds.height, screenSize.height); bounds.x = Math.min(Math.max(bounds.x, 0), screenSize.width - bounds.width); bounds.y = Math.min(Math.max(bounds.y, 0), screenSize.height - bounds.height); window.setBounds(bounds); }
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; }//w ww . j av a 2 s .c o m 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); }