Here you can find the source of getLocationToCenterOnScreen(Component comp)
Parameter | Description |
---|---|
comp | the Component to find a center for |
public static Point getLocationToCenterOnScreen(Component comp)
//package com.java2s; // This software is licensed under the GNU General Public License, import java.awt.Component; import java.awt.Dimension; import java.awt.Point; public class Main { /**//from w ww . j a va 2 s . c o m * given any component, returns a location for the top left corner of the component that will center it on the * screen * * @param comp * the Component to find a center for * @return Point the point at which component would be centered */ public static Point getLocationToCenterOnScreen(Component comp) { Dimension screenDim = comp.getToolkit().getScreenSize(); Dimension compDim = comp.getSize(); return new Point(Math.max(0, (screenDim.width - compDim.width) / 2), Math.max(0, (screenDim.height - compDim.height) / 2)); } }