List of usage examples for java.awt Dialog getParent
public Container getParent()
From source file:Main.java
public static void centerInOwner(Dialog dialog) { Container parent = dialog.getOwner(); if (parent != null && parent.isShowing()) centerInParent(dialog, dialog.getParent()); else//from w ww. j av a2 s .c o m center(dialog); }
From source file:Main.java
/** * 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. */// w ww. j a va2s. co m public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent, final double verticalPercent) { final Container parent = dialog.getParent(); if (parent == null || (parent.isVisible() == false)) { positionFrameOnScreen(dialog, horizontalPercent, verticalPercent); return; } final Dimension d = dialog.getSize(); final Dimension p = parent.getSize(); final int baseX = parent.getX(); final int baseY = parent.getY(); final int parentPointX = baseX + (int) (horizontalPercent * p.width); final int parentPointY = baseY + (int) (verticalPercent * p.height); final int dialogPointX = Math.max(0, parentPointX - (int) (horizontalPercent * d.width)); final int dialogPointY = Math.max(0, parentPointY - (int) (verticalPercent * d.height)); // make sure the dialog fits completely on the screen... final Rectangle s = parent.getGraphicsConfiguration().getBounds(); final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height); final Rectangle intersectedDialogBounds = r.intersection(s); if (intersectedDialogBounds.width < d.width) { r.x = s.width - d.width; r.width = d.width; } if (intersectedDialogBounds.height < d.height) { r.y = s.height - d.height; r.height = d.height; } final Rectangle finalIntersection = r.intersection(s); dialog.setBounds(finalIntersection); }
From source file:Main.java
/** * 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. *//*from w ww.jav a 2 s . c o m*/ 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); }
From source file:org.pentaho.reporting.libraries.designtime.swing.LibSwingUtil.java
/** * 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. *//*from w w w . j av a2s.c om*/ public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent, final double verticalPercent) { final Container parent = dialog.getParent(); if (parent == null || (parent.isVisible() == false)) { positionFrameOnScreen(dialog, horizontalPercent, verticalPercent); return; } final Dimension d = dialog.getSize(); final Dimension p = parent.getSize(); final int baseX = parent.getX(); final int baseY = parent.getY(); final int parentPointX = baseX + (int) (horizontalPercent * p.width); final int parentPointY = baseY + (int) (verticalPercent * p.height); final int dialogPointX = parentPointX - (int) (horizontalPercent * d.width); final int dialogPointY = parentPointY - (int) (verticalPercent * d.height); // make sure the dialog fits completely on the screen... final Rectangle s = parent.getGraphicsConfiguration().getBounds(); final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height); final Rectangle intersectedDialogBounds = r.intersection(s); if (intersectedDialogBounds.width < d.width) { r.x = s.width - d.width; r.width = d.width; } if (intersectedDialogBounds.height < d.height) { r.y = s.height - d.height; r.height = d.height; } final Rectangle finalIntersection = r.intersection(s); dialog.setBounds(finalIntersection); }