Java Screen Center getCenterPointRelativeToScreen(Dimension size)

Here you can find the source of getCenterPointRelativeToScreen(Dimension size)

Description

Gives the center point relative to the user's screen, given the size of some component.

License

Apache License

Parameter

Parameter Description
size Size of the component that is to be centered.

Return

Location of the component which makes the component to display in the center of the screen.

Declaration

public static Point getCenterPointRelativeToScreen(Dimension size) 

Method Source Code

//package com.java2s;
/*/*from w  ww. ja  va2s.c om*/
 * Copyright 2012 jMethods, Inc. 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;

public class Main {
    /**
     * Gives the center point relative to the user's screen, given the size of
     * some component.
     * 
     * @param size
     *            Size of the component that is to be centered.
     * @return Location of the component which makes the component to display in
     *         the center of the screen.
     */
    public static Point getCenterPointRelativeToScreen(Dimension size) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        return new Point((screenSize.width - size.width) / 2, (screenSize.height - size.height) / 2);
    }
}

Related

  1. getCenterLocation(Window window)
  2. getCenterLocationAWT( final java.awt.Component comp, final boolean onTitleBarIfWindow)
  3. getCenterPoint()
  4. getCenterPoint(Component parent, Component comp)
  5. getCenterPoint(final int w, final int h)
  6. getCenterPosition(Dimension d)
  7. getCenterPositionForComponent(int width, int heigth)
  8. getDimensionFromPercent(int percentWidth, int percentHeight)
  9. getFrameCenteredLocation(final java.awt.Component centerThis, final Component parent)