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());
 }
예제 #2
0
 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);
   }
 }
예제 #3
0
 /**
  * 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);
 }
예제 #5
0
 /**
  * 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));
 }
예제 #6
0
 /**
  * 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));
 }
예제 #7
0
 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);
 }