Code example for Component

Methods: getHeightgetToolkitgetWidthrepaintsetLocationvalidate

0
     * 
     * @param component 
     *            the component you want to center in window 
     */ 
    public static void centerComponentInWindow(Component component) {
        Dimension dimension = component.getToolkit().getScreenSize();
 
        component.setLocation((int) ((dimension.getWidth() - component.getWidth()) / 2),
                (int) ((dimension.getHeight() - component.getHeight()) / 2));
        component.validate();
        component.repaint();
    } 
 
    /** 
     * Use this static method if you want to center a component over another 
     * component. 
     * 
     * @param parent 
     *            the component you want to use to place it on 
     * @param toBeCentered