Java JFrame fitToDesktop(final JFrame frame)

Here you can find the source of fitToDesktop(final JFrame frame)

Description

fit To Desktop

License

BSD License

Parameter

Parameter Description
frame a parameter

Declaration

public static void fitToDesktop(final JFrame frame) 

Method Source Code

//package com.java2s;
/**/*  www.ja va2s .c om*/
 * <p>
 * This class contains useful methods for positioning, sizing, and manipulating JFrames and other
 * Window-like elements.
 * </p>
 * <p>
 * <span class="BSDLicense"> This software is distributed under the <a
 * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>. </span>
 * </p>
 * 
 * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu)
 */

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

public class Main {
    private static Rectangle desktopBounds = new Rectangle(0, 0, 640, 480);

    /**
     * @param frame
     * 
     * @created Feb 16, 2006
     * @author Ron Yeh
     */
    public static void fitToDesktop(final JFrame frame) {
        final int minWidth = (int) Math.min(frame.getBounds().getWidth(), desktopBounds.getWidth());
        final int minHeight = (int) Math.min(frame.getBounds().getHeight(), desktopBounds.getHeight());

        frame.setSize(minWidth, minHeight);
    }
}

Related

  1. fileChooser(JFrame frame, boolean saveDialog, String windowName, String filterName, String filterExtension)
  2. findFileOpen(JFrame frame, String ext, String desc)
  3. findFileSave(JFrame frame, String ext, String desc)
  4. findJFrame(Component c)
  5. findJFrame(Component myComponent)
  6. fullScreen(JFrame window)
  7. fullScreenUsingMaximise(JFrame w)
  8. fullScreenWithAPI(JFrame w)
  9. getFileSelection(JFrame parent, boolean onlyDirectories, String startingDir)