Here you can find the source of getCenterPointRelativeToScreen(Dimension size)
Parameter | Description |
---|---|
size | Size of the component that is to be centered. |
public static Point getCenterPointRelativeToScreen(Dimension size)
//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); } }