Java JFrame Center createCenteredJFrame(String title, int width, int height, boolean autoclose)

Here you can find the source of createCenteredJFrame(String title, int width, int height, boolean autoclose)

Description

creates a window with dimensions as component space

License

Open Source License

Parameter

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

Declaration

public static JFrame createCenteredJFrame(String title, int width, int height, boolean autoclose) 

Method Source Code


//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;
    }
}

Related

  1. centerWindow(JFrame frame)
  2. centerWindow(JFrame window)
  3. centerWindowInFrame(Component window, Window frame)
  4. centerWindowOnParent(Window w, JFrame parent)
  5. centerWithinDesktop(JInternalFrame frame)
  6. getCenteringFrame()
  7. getCenterOfTheWindow(JFrame frame)
  8. placeInCenter(JFrame frame)
  9. posiToScreenCenter(JFrame frame)