List of utility methods to do Window Center
void | centerOnParent(final Window child, final boolean absolute) Center on parent ( absolute true/false (exact center or 25% upper left) ) child.pack(); boolean useChildsOwner = child.getOwner() != null ? ((child.getOwner() instanceof JFrame) || (child.getOwner() instanceof JDialog)) : false; final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension parentSize = useChildsOwner ? child.getOwner().getSize() : screenSize; final Point parentLocationOnScreen = useChildsOwner ? child.getOwner().getLocationOnScreen() : new Point(0, 0); ... |
void | centerPosition(Window window, Window w, int width, int height) center Position int x = window.getX() + (window.getWidth() - width) / 2; int y = window.getY() + (window.getHeight() - height) / 2; w.setBounds(x, y, width, height); |
void | centerWindow(Window w) Center a window on the screen. Dimension screenSize = w.getToolkit().getScreenSize(); Dimension windowSize = w.getSize(); int x = (screenSize.width - windowSize.width) / 2; int y = (screenSize.height - windowSize.height) / 2; w.setLocation(x, y); |
void | packAndCenterWindow(Window dlg) pack And Center Window dlg.pack(); dlg.pack(); Dimension size = dlg.getSize(); Dimension viewableScreenSize = getViewableScreenSize(); if (size.height > viewableScreenSize.height) size.height = viewableScreenSize.height; if (size.width > viewableScreenSize.width) size.width = viewableScreenSize.width; ... |
void | packAndDisplayInCenterOfScreen(final Window f) Packs a Window and display it in center of the screen. f.pack(); displayInCenterOfScreen(f); |
void | positionCenterScreen(Window window) position Center Screen Dimension maxDimension = Toolkit.getDefaultToolkit().getScreenSize(); Dimension wSize = window.getSize(); int maxWidth = maxDimension.width; int maxHeight = maxDimension.height; if (wSize.height > maxHeight) { wSize.height = maxHeight; if (wSize.width > maxWidth) { ... |
void | showCentered(Window window) Shows the window centered on its parent window, or the screen if there is no parent window. center(window); window.setVisible(true); |
void | showCenterWindow(Window parent, Window window) show Center Window positionCenterWindow(parent, window); window.setVisible(true); |