private void loadBounds(Dialog d, String key) { d.pack(); // Position the dialog according to the history Rectangle lastBounds = (Rectangle) EditorState.get(key); if (lastBounds != null) { d.setBounds(lastBounds); } else { // no history, center it on the screen Dimension dim = d.getPreferredSize(); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = Math.max(0, (screen.width - dim.width) / 2); int y = Math.max(0, (screen.height - dim.height) / 2); d.setLocation(x, y); } }
/** * Positions the specified dialog at a position relative to its parent. * * @param dialog the dialog to be positioned. * @param horizontalPercent the relative location. * @param verticalPercent the relative location. */ public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent, final double verticalPercent) { final Dimension d = dialog.getSize(); final Container parent = dialog.getParent(); final Dimension p = parent.getSize(); final int baseX = parent.getX() - d.width; final int baseY = parent.getY() - d.height; final int w = d.width + p.width; final int h = d.height + p.height; int x = baseX + (int) (horizontalPercent * w); int y = baseY + (int) (verticalPercent * h); // make sure the dialog fits completely on the screen... final Rectangle s = getMaximumWindowBounds(); x = Math.min(x, (s.width - d.width)); x = Math.max(x, 0); y = Math.min(y, (s.height - d.height)); y = Math.max(y, 0); dialog.setBounds(x + s.x, y + s.y, d.width, d.height); }
/** * Positions the specified dialog at a position relative to its parent. * * @param dialog the dialog to be positioned. * @param horizontalPercent the relative location. * @param verticalPercent the relative location. */ public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent, final double verticalPercent) { final Dimension d = dialog.getSize(); final Container parent = dialog.getParent(); final Dimension p = parent.getSize(); final int baseX = parent.getX() - d.width; final int baseY = parent.getY() - d.height; final int w = d.width + p.width; final int h = d.height + p.height; int x = baseX + (int) (horizontalPercent * w); int y = baseY + (int) (verticalPercent * h); // make sure the dialog fits completely on the screen... final Rectangle s = getMaximumWindowBounds(); x = Math.min(x, (s.width - d.width)); x = Math.max(x, 0); y = Math.min(y, (s.height - d.height)); y = Math.max(y, 0); dialog.setBounds(x + s.x, y + s.y, d.width, d.height); }
protected synchronized Dialog createGotoDialog() { if (gotoDialog == null) { gotoDialog = DialogSupport.createDialog(LocaleSupport.getString("goto-title"), // NOI18N gotoPanel, false, // non-modal gotoButtons, false, // sidebuttons, 0, // defaultIndex = 0 => gotoButton 1, // cancelIndex = 1 => cancelButton this // listener ); gotoDialog.pack(); // Position the dialog according to the history Rectangle lastBounds = (Rectangle) EditorState.get(BOUNDS_KEY); if (lastBounds != null) { gotoDialog.setBounds(lastBounds); } else { // no history, center it on the screen Dimension dim = gotoDialog.getPreferredSize(); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = Math.max(0, (screen.width - dim.width) / 2); int y = Math.max(0, (screen.height - dim.height) / 2); gotoDialog.setLocation(x, y); } return gotoDialog; } else { gotoDialog.toFront(); return null; } }
gotoDialog.setBounds( lastBounds ); } else { // no history, center it on the screen Dimension dim = gotoDialog.getPreferredSize();
dialog.setBounds( finalIntersection );
if( null != lastBounds ) { lastBounds.width = Math.max( lastBounds.width, SIZE_PREFERRED_WIDTH+extraW ); dialog.setBounds( lastBounds );
/** * Positions the specified dialog at a position relative to its parent. * * @param dialog the dialog to be positioned. * @param horizontalPercent the relative location. * @param verticalPercent the relative location. */ public static void positionDialogRelativeToParent(Dialog dialog, double horizontalPercent, double verticalPercent) { Container parent = dialog.getParent(); if (parent == null) { centerFrameOnScreen(dialog); return; } Dimension d = dialog.getSize(); Dimension p = parent.getSize(); int baseX = parent.getX(); int baseY = parent.getY(); int x = baseX + (int) (horizontalPercent * p.width); int y = baseY + (int) (verticalPercent * p.height); // make sure the dialog fits completely on the screen... Rectangle s = parent.getGraphicsConfiguration().getBounds(); Rectangle r = new Rectangle(x, y, d.width, d.height); dialog.setBounds(r.intersection(s)); }
/** * Positions the specified dialog at a position relative to its parent. * * @param dialog the dialog to be positioned. * @param horizontalPercent the relative location. * @param verticalPercent the relative location. */ public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent, final double verticalPercent) { final Container parent = dialog.getParent(); if (parent == null) { centerFrameOnScreen(dialog); return; } final Dimension d = dialog.getSize(); final Dimension p = parent.getSize(); final int baseX = parent.getX(); final int baseY = parent.getY(); final int x = baseX + (int) (horizontalPercent * p.width); final int y = baseY + (int) (verticalPercent * p.height); // make sure the dialog fits completely on the screen... final Rectangle s = parent.getGraphicsConfiguration().getBounds(); final Rectangle r = new Rectangle(x, y, d.width, d.height); dialog.setBounds(r.intersection(s)); }
dialog.setBounds( finalIntersection );