Java Screen Center locateOnScreenCenter(Component component)

Here you can find the source of locateOnScreenCenter(Component component)

Description

Locates the given component on the screen's center.

License

Open Source License

Parameter

Parameter Description
component the component to be centered

Declaration

public static void locateOnScreenCenter(Component component) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.*;

public class Main {
    /**//from w ww  .  j a v a2s .  c  o  m
      * Locates the given component on the screen's center.
      *
      * @param component the component to be centered
      */
    public static void locateOnScreenCenter(Component component) {
        Dimension paneSize = component.getSize();
        Dimension screenSize = component.getToolkit().getScreenSize();
        component.setLocation((screenSize.width - paneSize.width) / 2, (screenSize.height - paneSize.height) / 2);
    }
}

Related

  1. getDimensionFromPercent(int percentWidth, int percentHeight)
  2. getFrameCenteredLocation(final java.awt.Component centerThis, final Component parent)
  3. getFrameOnCenterLocationPoint(Window window)
  4. getLocationToCenterOnScreen(Component comp)
  5. getPercentageOnScreen(Point location, Dimension size, Rectangle screen)
  6. moveToCenter(Component componentToMove, Component componentToCenterOver)
  7. moveToScreenCenter(Window w)
  8. packAndCenter(Window wind)
  9. packAndCenter(Window window)