If You can center a component You can also center a component at display. The follow class can both.
all rights reserved © Bastie - Sebastian Ritter @: w³: http://www.Bastie.depackagede.bastie.howto.gui;importjava.awt.*;public classGUITool {/** instance of toolkit */final staticToolkit defaultToolkit = Toolkit.getDefaultToolkit ();/** Constructor */publicGUITool () {}/** This class method center a component at display. * @param Component to center * @pattern MethodDelegate */public static voidcenter (finalComponent toCenter) { Component main =newDefaultComponent ();// Set the size of main component to size from displaymain.setSize(Toolkit.getDefaultToolkit().getScreenSize());// Delegate to method center (Component, Component)GUITool.center (main, toCenter); }/** This class method center a component toCenter * at the other component main * @param Component main * @param Component toCenter */public static voidcenter (finalComponent main,finalComponent toCenter) { toCenter.setLocation ((int)(main.getSize().width /2-toCenter.getSize().width /2+main.getLocation().getX()), (int)(main.getSize().height /2-toCenter.getSize().height /2+main.getLocation().getY()) ); }/** Default implementation of abstract class Component */public static classDefaultComponentextendsComponent {} }