private void adjustWindowSize(ContainerWrapper parent) { BoundSize wBounds = lc.getPackWidth(); BoundSize hBounds = lc.getPackHeight(); if (wBounds == null && hBounds == null) return; Window win = ((Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) parent.getComponent())); if (win == null) return; Dimension prefSize = win.getPreferredSize(); .... }
static void centerOnScreen(Window window) { Toolkit t = Toolkit.getDefaultToolkit(); Dimension screenSize = t.getScreenSize(); Dimension frameSize = window.getPreferredSize(); double x = (screenSize.getWidth() - frameSize.getWidth()) / 2; double y = (screenSize.getHeight() - frameSize.getHeight()) / 2; window.setLocation((int) x, (int) y); }
static void centerOnScreen(Window window) { Toolkit t = Toolkit.getDefaultToolkit(); Dimension screenSize = t.getScreenSize(); Dimension frameSize = window.getPreferredSize(); double x = (screenSize.getWidth() - frameSize.getWidth()) / 2; double y = (screenSize.getHeight() - frameSize.getHeight()) / 2; window.setLocation((int) x, (int) y); }
static void centerWindowInScreen(final Window window) { final Dimension screenSize= window.getToolkit().getScreenSize(); final Dimension windowSize= window.getPreferredSize(); window.setLocation( (int) (screenSize.getWidth() / 2 - windowSize.getWidth() / 2), (int) (screenSize.getHeight() / 2 - windowSize.getHeight() / 2)); } /**
/** * Ensures that a window stays within the current screen's bounds * while changing the position of the window as little as possible. * * @param preferredLeftTop The preferred left-top location of the window * @param window The window */ public static void keepInScreenBounds(final Point preferredLeftTop, final Window window) { final Rectangle preferredBounds = new Rectangle( preferredLeftTop, window.getPreferredSize() ); window.setLocation( ScreenUtils.ensureOnScreen(preferredBounds).getLocation() ); }
screenBounds.height -= screenInsets.top + screenInsets.bottom; Dimension preferredSize = window.getPreferredSize();
screenBounds.height -= screenInsets.top + screenInsets.bottom; window.pack(); Dimension preferredSize = window.getPreferredSize();
window.setSize(window.getPreferredSize()); org.appdapter.gui.browse.Utility.centerWindow(window); if (showASAP) {