Java JFrame Center centerBigFrame(JFrame frame, int maxWidth, int maxHeight, double scaling, int minHeight)

Here you can find the source of centerBigFrame(JFrame frame, int maxWidth, int maxHeight, double scaling, int minHeight)

Description

Center a big window

License

Open Source License

Declaration


public static Dimension centerBigFrame(JFrame frame, int maxWidth, int maxHeight, double scaling,
        int minHeight) 

Method Source Code

//package com.java2s;
/*//from   w  w w .j a v  a2  s  .  c  om
**    Copyright (C) 2003-2012 Institute for Systems Biology 
**                            Seattle, Washington, USA. 
**
**    This library is free software; you can redistribute it and/or
**    modify it under the terms of the GNU Lesser General Public
**    License as published by the Free Software Foundation; either
**    version 2.1 of the License, or (at your option) any later version.
**
**    This library is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**    Lesser General Public License for more details.
**
**    You should have received a copy of the GNU Lesser General Public
**    License along with this library; if not, write to the Free Software
**    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import java.awt.Dimension;

import java.awt.Toolkit;

import javax.swing.JFrame;

public class Main {
    /***************************************************************************
    **
    ** Center a big window
    */

    public static Dimension centerBigFrame(JFrame frame, int maxWidth, int maxHeight, double scaling,
            int minHeight) {

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int winWidth = screenSize.width - 40;
        int winHeight = screenSize.height - 150;
        if (winWidth > maxWidth) {
            winWidth = maxWidth;
        }
        if (winHeight > maxHeight) {
            winHeight = maxHeight;
        }
        winWidth = (int) (scaling * (double) winWidth);
        winHeight = (int) (scaling * (double) winHeight);
        if (winHeight < minHeight) {
            winHeight = (minHeight > screenSize.height) ? screenSize.height : minHeight;
        }
        frame.setSize(winWidth, winHeight);
        Dimension frameSize = frame.getSize();
        int x = (screenSize.width - frameSize.width) / 2;
        int y = (screenSize.height - frameSize.height) / 2;
        frame.setLocation(x, y);
        return (new Dimension(winWidth, winHeight));
    }
}

Related

  1. alignCenter(JInternalFrame internalFrame)
  2. center(JFrame frame)
  3. center(JFrame frame)
  4. center(JFrame parent, JInternalFrame dialog)
  5. centerAndSizeFrame(JFrame frame)
  6. centerDialog(final JFrame frame, JDialog dialog)
  7. centerDialog(JDialog dialog, JFrame frame)
  8. centerDialog(JDialog dialog, JFrame parent)
  9. centerDialogIntoFrame(java.awt.Component p_CompToBePositioned, javax.swing.JFrame p_MainFrame)