List of usage examples for java.awt Window setLocation
@Override public void setLocation(int x, int y)
The method changes the geometry-related data.
From source file:Main.java
public static void centerOnScreenAtLocation(Window window, Point desiredLocation) { GraphicsDevice currentScreen = getCurrentScreen(desiredLocation, window.getSize()); Rectangle2D screenBounds = currentScreen.getDefaultConfiguration().getBounds(); window.setLocation((int) screenBounds.getCenterX() - (window.getWidth() / 2), (int) screenBounds.getCenterY() - (window.getHeight() / 2)); }
From source file:Main.java
public static void center(Window window) { final Dimension size = window.getSize(); final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); final int locX = (screen.width - size.width) / 2; final int locY = (screen.height - size.height) / 2; window.setLocation(locX, locY); }
From source file:Main.java
public static void centerOnScreen(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension windowSize = window.getSize(); int x = (screenSize.width - windowSize.width) / 2; int y = (screenSize.height - windowSize.height) / 2; window.setLocation(x, y); }
From source file:Main.java
/** * Centers the {@link java.awt.Window} on the display * * @param window/* w w w . jav a2 s.c o m*/ * Window to center */ public static void centerWindow(Window window) { Rectangle boundsOfAvailableSpace = getBoundsOfAvailableDisplaySpace(window); int offsetX = (boundsOfAvailableSpace.width - window.getWidth()) / 2; int offsetY = (boundsOfAvailableSpace.height - window.getHeight()) / 2; window.setLocation(offsetX, offsetY); }
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 source file:Main.java
public static void centerOnScreen(final Window window) { final Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension windowSize = window.getSize(); final int x = (screensize.width - windowSize.width) / 2; final int y = (screensize.height - windowSize.height) / 2; window.setLocation(x, y); }
From source file:Main.java
/** Centers the given window within the specified bounds. */ public static void centerWindow(final Rectangle bounds, final Window window) { final Dimension w = window.getSize(); int x = bounds.x + (bounds.width - w.width) / 2; int y = bounds.y + (bounds.height - w.height) / 2; if (x < 0) x = 0;/*from ww w .j ava2s. c o m*/ if (y < 0) y = 0; window.setLocation(x, y); }
From source file:Main.java
public static void center(Window window) { window.pack();/*from w ww . j a v a 2s .co 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
/** * Centers the window on the screen./*from w w w .j ava 2 s . co m*/ * * @param window The window to center. * @return The location or top-left corner. */ public static Point centerOnScreen(Window window) { Dimension screenSize = getScreenSize(window); Dimension windowSize = window.getSize(); int x = (int) ((screenSize.getWidth() - windowSize.getWidth()) / 2); int y = (int) ((screenSize.getHeight() - windowSize.getHeight()) / 2); window.setLocation(x, y); return window.getLocation(); }
From source file:Main.java
public static void center(Window window, double ratio) { Rectangle bounds = window.getGraphicsConfiguration().getBounds(); int width = bounds.width / 2; int height = bounds.height / 2; int centerX = (int) (bounds.x + bounds.width * ratio); int centerY = (int) (bounds.y + bounds.height * ratio); window.setLocation(centerX - width / 2, centerY - height / 2); window.setPreferredSize(new Dimension(width, height)); window.pack();//w w w . j a va 2 s . com }