Here you can find the source of locateOnScreenCenter(Component component)
Parameter | Description |
---|---|
component | the component to be centered |
public static void locateOnScreenCenter(Component component)
//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); } }