/** Center a component in the middle of the screen. */
  public static void centerComponent(java.awt.Component component) {
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    java.awt.Dimension size = component.getSize();

    screenSize.height = screenSize.height / 2;
    screenSize.width = screenSize.width / 2;

    size.height = size.height / 2;
    size.width = size.width / 2;

    component.setLocation(screenSize.width - size.width, screenSize.height - size.height);
  }
Exemplo n.º 2
0
 public static void centerFrame(java.awt.Component c) {
   java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
   c.setLocation(
       (int) ((tk.getScreenSize().getWidth() - c.getWidth()) / 2),
       (int) ((tk.getScreenSize().getHeight() - c.getHeight()) / 2));
 }