protected void centerWindow(Window win) { Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); // If larger than screen, reduce window width or height if (screenDim.width < win.getSize().width) { win.setSize(screenDim.width, win.getSize().height); } if (screenDim.height < win.getSize().height) { win.setSize(win.getSize().width, screenDim.height); } // Center Frame, Dialogue or Window on screen int x = (screenDim.width - win.getSize().width) / 2; int y = (screenDim.height - win.getSize().height) / 2; win.setLocation(x, y); }
/** * Sets the location of the specified window so that it is centered on screen. * * @param window The window to be centered. */ public static void centerWindowOnScreen(Window window) { final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension size = window.getSize(); if (size.height > screenSize.height) { size.height = screenSize.height; } if (size.width > screenSize.width) { size.width = screenSize.width; } window.setLocation((screenSize.width - size.width) / 2, (screenSize.height - size.height) / 2); }
/** * Centers the window over a component (usually another window). * The window must already have been sized. */ public static void centerWindowOnComponent(Window window, Component over) { if ((over == null) || !over.isShowing()) { centerWindowOnScreen(window); return; } Point parentLocation = over.getLocationOnScreen(); Dimension parentSize = over.getSize(); Dimension size = window.getSize(); // Center it. int x = parentLocation.x + (parentSize.width - size.width) / 2; int y = parentLocation.y + (parentSize.height - size.height) / 2; // Now, make sure it's onscreen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // This doesn't actually work on the Mac, where the screen // doesn't necessarily start at 0,0 if (x + size.width > screenSize.width) x = screenSize.width - size.width; if (x < 0) x = 0; if (y + size.height > screenSize.height) y = screenSize.height - size.height; if (y < 0) y = 0; window.setLocation(x, y); }
private static void doCentre(Window dialog, Dimension parentDim) { Dimension dialogDim = dialog.getSize(); int x = Math.max(0, parentDim.width / 2 - dialogDim.width / 2); int y = Math.max(0, parentDim.height / 2 - dialogDim.height / 2); dialog.setLocation(x, y); }
private static void doShowCentred(Window parent, Window dialog) { if (parent == null) { doCentre(dialog, Toolkit.getDefaultToolkit().getScreenSize()); } else { doCentre(dialog, parent.getSize()); } dialog.setVisible(true); }
public static void centerOnScreen(Window w, Window parent) { Rectangle r = new Rectangle(); if (parent == null) { r.setSize(Toolkit.getDefaultToolkit().getScreenSize()); } else { 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); }
public static Window center(Window w, Window reference) { double refCenterX = reference.getX() + (reference.getSize().getWidth()/2); double refCenterY = reference.getY() + (reference.getSize().getHeight()/2); int newX = (int) (refCenterX - (w.getSize().getWidth()/2)); int newY = (int) (refCenterY - (w.getSize().getHeight()/2)); w.setLocation(newX, newY); return w; }
public static void placeInCenterScreen(Window win) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frame = win.getSize(); win.setLocation((screen.width - frame.width) / 2, (screen.height - frame.height) / 2); }
private static void doCentre(Window dialog, Dimension parentDim) { Dimension dialogDim = dialog.getSize(); int x = Math.max(0, parentDim.width / 2 - dialogDim.width / 2); int y = Math.max(0, parentDim.height / 2 - dialogDim.height / 2); dialog.setLocation(x, y); }
private void centerOnScreen( Window window ) { Dimension frameSize = window.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 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 ); }
public void mousePressed( MouseEvent e ) { final Window win = SwingUtilities.getWindowAncestor( e.getComponent() ); if( win != null ) { initialMouse = e.getPoint(); SwingUtilities.convertPointToScreen( initialMouse, e.getComponent() ); initialSize = win.getSize(); } }
/** * Description of the Method * * @param w Description of Parameter */ public static void centerOnScreen(Window w) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = w.getSize(); w.setLocation((screenSize.width - size.width) / 2, (screenSize.height - size.height) / 2); }
/** * Moves the given window to the center of the screen */ public static void centerWindow(Window win) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dim = win.getSize(); win.setLocation((screen.width / 2) - (dim.width / 2), (screen.height / 2) - (dim.height / 2)); }
/** Centre a Window, Frame, JFrame, Dialog, etc. */ public static void centre(final 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); }
public static void placeInUpperLeftScreen(Window win) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frame = win.getSize(); win.setLocation(screen.width / 4 - frame.width / 2, screen.height / 4 - frame.height / 2); }
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); }
public static void centerOnComponet(Window target, JComponent parent) { Dimension targetSize = target.getSize(); Point location = parent.getLocationOnScreen(); Dimension sourceSize = parent.getSize(); Point sourceCenter = new Point(location.x + sourceSize.width / 2, location.y + sourceSize.height / 2); Point frameLocation = new Point(sourceCenter.x - targetSize.width / 2, sourceCenter.y - targetSize.height / 2); target.setLocation(frameLocation); }
private static void doShowCentred(Window parent, Window dialog) { if (parent == null) { doCentre(dialog, Toolkit.getDefaultToolkit().getScreenSize()); } else { doCentre(dialog, parent.getSize()); } dialog.setVisible(true); }
@Override public void windowClosed(WindowEvent e) { if (e.getSource() == gui) { return; } popoutDisposed(getChannelFromWindow(e.getSource())); if (savePopoutAttributes) { Window window = e.getWindow(); dialogsAttributes.add(0, new LocationAndSize( window.getLocation(), window.getSize())); } }
public static void centerOnScreen(Window target) { DisplayMode displayMode = target.getGraphicsConfiguration().getDevice().getDisplayMode(); int displayHeight = displayMode.getHeight(); int displayWidth = displayMode.getWidth(); Dimension targetSize = target.getSize(); Point frameLocation = new Point(displayWidth / 2 - targetSize.width / 2, displayHeight / 2 - targetSize.height / 2); target.setLocation(frameLocation); }