Java JFrame Center centerWindow(JFrame window)

Here you can find the source of centerWindow(JFrame window)

Description

center Window

License

Apache License

Declaration

public static void centerWindow(JFrame window) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.*;
import javax.swing.*;

public class Main {
    public static void centerWindow(JFrame window) {
        //center window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = window.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }/*from www  . ja v  a 2 s. c o m*/
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    }
}

Related

  1. centerPoint(int width, int height, JFrame frame)
  2. centerPosition(JFrame invokerFrame, Window w, int width, int height)
  3. centerWindow(JFrame frame)
  4. centerWindow(JFrame frame)
  5. centerWindow(JFrame frame)
  6. centerWindowInFrame(Component window, Window frame)
  7. centerWindowOnParent(Window w, JFrame parent)
  8. centerWithinDesktop(JInternalFrame frame)
  9. createCenteredJFrame(String title, int width, int height, boolean autoclose)