/** * Randomly picks the location of a new window, such that it fits completely on the screen. * * @param desktopPane the desktop pane that the frame is being added to. * @param frame the JInternalFrame which is being added. * @param desiredSize the desired dimensions of the frame. */ private static void setGoodBounds( JInternalFrame frame, JDesktopPane desktopPane, Dimension desiredSize) { RandomUtil randomUtil = RandomUtil.getInstance(); Dimension desktopSize = desktopPane.getSize(); Dimension d = new Dimension(desiredSize); int tx = desktopSize.width - d.width; int ty = desktopSize.height - d.height; if (tx < 0) { tx = 0; d.width = desktopSize.width; } else { tx = (int) (randomUtil.nextDouble() * tx); } if (ty < 0) { ty = 0; d.height = desktopSize.height; } else { ty = (int) (randomUtil.nextDouble() * ty); } frame.setBounds(tx, ty, d.width, d.height); }