Java JDesktopPane makeCenter(JDesktopPane desktop)

Here you can find the source of makeCenter(JDesktopPane desktop)

Description

make Center

License

Apache License

Declaration

public static void makeCenter(JDesktopPane desktop) 

Method Source Code


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

import java.awt.Component;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;

public class Main {
    public static void makeCenter(Component component) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = component.getSize();

        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }//  w  w  w.  j  a v a  2  s  .  c  o  m

        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        component.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    }

    public static void makeCenter(JDesktopPane desktop) {
        JInternalFrame[] frames = desktop.getAllFrames();
        for (JInternalFrame frame : frames) {
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = frame.getSize();

            if (frameSize.height > screenSize.height) {
                frameSize.height = screenSize.height;
            }

            if (frameSize.width > screenSize.width) {
                frameSize.width = screenSize.width;
            }
            frame.setFrameIcon(null);
            frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        }
    }
}

Related

  1. arrangeIcons(JDesktopPane desktop)
  2. arrangeMinifiedWindows(JDesktopPane desktop)
  3. cascade(JDesktopPane desktopPane, int layer)
  4. moveOff(JDesktopPane desktop)
  5. tileHorizontal(JDesktopPane desktop)
  6. tileVertical(JDesktopPane desktop)