public void doLayout() { if (view != null) { view.setSize(view.getPreferredSize()); visibleRect = getVisibleRect(); view.setLocation(visibleRect.x, visibleRect.y); } glassPane.setLocation(0, 0); glassPane.setSize(getWidth(), getHeight()); }
public static void center(Component c, Component rel) { if (rel != null) { c.setLocation( rel.getLocation().x + rel.getSize().width / 2 - c.getSize().width / 2, rel.getLocation().y + rel.getSize().height / 2 - c.getSize().height / 2); } else { c.setLocation( Toolkit.getDefaultToolkit().getScreenSize().width / 2 - c.getSize().width / 2, +Toolkit.getDefaultToolkit().getScreenSize().height / 2 - c.getSize().height / 2); } }
/** * Changes the frame's location to a more central screen location * * @param frame the frame to be moved * @param X how far right to move the frame * @param Y how far down to move the frame */ public static void changeFrameLocation(Component frame, int X, int Y) { Point location = frame.getLocation(); // the window's current location // move the window over and down a certain amount of pixels location.translate(X, Y); // set the location frame.setLocation(location); }
public static void setRelativeBounds( @NotNull Component parent, @NotNull Rectangle bounds, @NotNull Component child, @NotNull Container validationParent) { validationParent.add(parent); parent.setBounds(bounds); parent.validate(); child.setLocation(SwingUtilities.convertPoint(child, 0, 0, parent)); validationParent.remove(parent); }
/** * A very nice trick is to center dialog with their parent. * * @param parent The parent <code>Component</code> * @param child The <code>Component</code> to center */ public static void centerComponentChild(Component parent, Component child) { Rectangle par = parent.getBounds(); Rectangle chi = child.getBounds(); child.setLocation( new Point(par.x + (par.width - chi.width) / 2, par.y + (par.height - chi.height) / 2)); }
/** * A very nice trick is to center windows on screen, this method helps you to to that. * * @param compo The <code>Component</code> to center */ public static void centerComponent(Component compo) { compo.setLocation( new Point( (getScreenDimension().width - compo.getSize().width) / 2, (getScreenDimension().height - compo.getSize().height) / 2)); }
private static void locateOnScreen(Component component) { Dimension paneSize = component.getSize(); Dimension screenSize = component.getToolkit().getScreenSize(); component.setLocation( (screenSize.width - paneSize.width) / 2, (screenSize.height - paneSize.height) / 2); }