Here you can find the source of createCenteredJFrame(String title, int width, int height, boolean autoclose)
Parameter | Description |
---|---|
title | the title of the window |
width | width of the component space |
height | height of the component space |
autoclose | if true the default close operation will be set to exit |
public static JFrame createCenteredJFrame(String title, int width, int height, boolean autoclose)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; public class Main { public static final Dimension DESKTOP_SIZE = Toolkit.getDefaultToolkit().getScreenSize(); /**/*from w ww .ja v a 2s. co m*/ * creates a window with dimensions as component space * @param title the title of the window * @param width width of the component space * @param height height of the component space * @param autoclose if true the default close operation will be set to exit */ public static JFrame createCenteredJFrame(String title, int width, int height, boolean autoclose) { JFrame frame = new JFrame(title); if (autoclose) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(width + 16, height + 38); frame.setLocation((DESKTOP_SIZE.width - width + 16) / 2, (DESKTOP_SIZE.height - height + 38) / 2); return frame; } }