/** * Positions the specified frame at a relative position in the screen, where 50% is considered * to be the center of the screen. * * @param frame the frame. * @param horizontalPercent the relative horizontal position of the frame (0.0 to 1.0, * where 0.5 is the center of the screen). * @param verticalPercent the relative vertical position of the frame (0.0 to 1.0, where * 0.5 is the center of the screen). */ public static void positionFrameOnScreen(final Window frame, final double horizontalPercent, final double verticalPercent) { final Rectangle s = getMaximumWindowBounds(); final Dimension f = frame.getSize(); final int w = Math.max(s.width - f.width, 0); final int h = Math.max(s.height - f.height, 0); final int x = (int) (horizontalPercent * w) + s.x; final int y = (int) (verticalPercent * h) + s.y; frame.setBounds(x, y, f.width, f.height); }
/** * Positions the specified frame at a relative position in the screen, where 50% is considered * to be the center of the screen. * * @param frame the frame. * @param horizontalPercent the relative horizontal position of the frame (0.0 to 1.0, * where 0.5 is the center of the screen). * @param verticalPercent the relative vertical position of the frame (0.0 to 1.0, where * 0.5 is the center of the screen). */ public static void positionFrameOnScreen(final Window frame, final double horizontalPercent, final double verticalPercent) { final Rectangle s = getMaximumWindowBounds(); final Dimension f = frame.getSize(); final int w = Math.max(s.width - f.width, 0); final int h = Math.max(s.height - f.height, 0); final int x = (int) (horizontalPercent * w) + s.x; final int y = (int) (verticalPercent * h) + s.y; frame.setBounds(x, y, f.width, f.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); }
/** * 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); }