Exemplo n.º 1
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));
 }
Exemplo n.º 2
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));
 }