Here you can find the source of centerAndSizeFrame(JFrame frame)
Parameter | Description |
---|---|
JFrame | to be configured |
public static void centerAndSizeFrame(JFrame frame)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; public class Main { /**//from w w w . j av a 2 s . c o m * Centeres the frame on the user's screen and sets the size of it to a reasonable size. * * @param JFrame to be configured * @return void */ public static void centerAndSizeFrame(JFrame frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int height = screenSize.height; int width = screenSize.width; frame.setSize(width / 2, height / 2); frame.setLocationRelativeTo(null); } }