Here you can find the source of posiToScreenCenter(JFrame frame)
Parameter | Description |
---|---|
frame | a parameter |
public static void posiToScreenCenter(JFrame frame)
//package com.java2s; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; public class Main { /**/*from www . j av a 2s .c o m*/ * Set frame to location screen center. * * @param frame * */ public static void posiToScreenCenter(JFrame frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) frameSize.width = screenSize.width; frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); } }