Here you can find the source of createCenteredWindow(String title, Dimension size, JPanel panel, boolean exitOnClose)
Parameter | Description |
---|---|
title | Window title. |
size | Window size. |
panel | Window contents panel. |
exitOnClose | If true closes the application |
public static JFrame createCenteredWindow(String title, Dimension size, JPanel panel, boolean exitOnClose)
//package com.java2s; /**/*w w w . j av a2 s .co m*/ * JFrameUtils * Created by Lu?s F. Loureiro, github.com/nczeroshift * Under MIT license */ import javax.swing.*; import java.awt.*; public class Main { /** * Create a simple centered window(JFrame). * @param title Window title. * @param size Window size. * @param panel Window contents panel. * @param exitOnClose If true closes the application * @return New JFrame instance. */ public static JFrame createCenteredWindow(String title, Dimension size, JPanel panel, boolean exitOnClose) { JFrame frame = new JFrame(title); frame.setSize(size); frame.setPreferredSize(size); if (exitOnClose) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); else frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.add(panel); frame.pack(); frame.setLocationRelativeTo(null); return frame; } }