Java Screen Center setLocationCentral(final Component component)

Here you can find the source of setLocationCentral(final Component component)

Description

set Location Central

License

Open Source License

Parameter

Parameter Description
component a parameter

Declaration

public static void setLocationCentral(final Component component) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Manchester Centre for Integrative Systems Biology
 * University of Manchester/*from w w  w.j  a v  a 2  s  .c o m*/
 * Manchester M1 7ND
 * United Kingdom
 * 
 * Copyright (C) 2007 University of Manchester
 * 
 * This program is released under the Academic Free License ("AFL") v3.0.
 * (http://www.opensource.org/licenses/academic.php)
 *******************************************************************************/

import java.awt.*;

public class Main {
    /**
     * 
     * @param component
     */
    public static void setLocationCentral(final Component component) {
        final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
        final Dimension frameDimension = component.getSize();
        final int x = (screenDimension.width - frameDimension.width) / 2;
        final int y = (screenDimension.height - frameDimension.height) / 2;
        component.setLocation(x, y);
    }
}

Related

  1. setCenteredInScreen(Component frame)
  2. setCenteredRectangle(int rectangleWidth, int rectangleHeight)
  3. setCenterLocation(final Window window)
  4. setCenterPosition(final Frame frame)
  5. setComponentLocationOnCenter(Component component)
  6. setLocationOnScreenToCenteredWithin(java.awt.Window window, java.awt.Component root)
  7. setLocationToCenter(Window window)
  8. setSizeAndCenterOnSreen(Window window, double widthFactor, double heightFactor)
  9. setupImage(BufferedImage image, int centerPos, int size, int maxSizePercentage)