Here you can find the source of locateOnOpticalScreenCenter(Component component)
Parameter | Description |
---|---|
component | the component to be centered |
public static void locateOnOpticalScreenCenter(Component component)
//package com.java2s; import java.awt.Component; import java.awt.Dimension; public class Main { /**// w ww . j av a 2 s. c om * Locates the given component on the screen's center. * * @param component the component to be centered */ public static void locateOnOpticalScreenCenter(Component component) { Dimension paneSize = component.getSize(); Dimension screenSize = component.getToolkit().getScreenSize(); component.setLocation((screenSize.width - paneSize.width) / 2, (int) ((screenSize.height - paneSize.height) * 0.45)); } }