Java JFrame Center centerAndSizeFrame(JFrame frame)

Here you can find the source of centerAndSizeFrame(JFrame frame)

Description

Centeres the frame on the user's screen and sets the size of it to a reasonable size.

License

Open Source License

Parameter

Parameter Description
JFrame to be configured

Return

void

Declaration

public static void centerAndSizeFrame(JFrame frame) 

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 {
    /**//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);
    }
}

Related

  1. alignCenter(JInternalFrame internalFrame)
  2. center(JFrame frame)
  3. center(JFrame frame)
  4. center(JFrame parent, JInternalFrame dialog)
  5. centerBigFrame(JFrame frame, int maxWidth, int maxHeight, double scaling, int minHeight)
  6. centerDialog(final JFrame frame, JDialog dialog)
  7. centerDialog(JDialog dialog, JFrame frame)
  8. centerDialog(JDialog dialog, JFrame parent)