Java JDialog resizeDialogToScreen(JDialog dialog)

Here you can find the source of resizeDialogToScreen(JDialog dialog)

Description

Update the size of the dialog to ensure it will fit on the screen.

License

Open Source License

Parameter

Parameter Description
dialog The dialog to be resized.

Declaration

public static void resizeDialogToScreen(JDialog dialog) 

Method Source Code

//package com.java2s;
/*//  w ww. j  a v a  2  s . c o m
 * CoreUtility.java
 * Copyright 2002-2003 (C) B. K. Oxley (binkley)
 * <binkley@alumni.rice.edu>
 *
 * 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
 *
 * Created on Februrary 4th, 2002.
 */

import java.awt.Dimension;

import java.awt.GraphicsEnvironment;

import java.awt.Rectangle;

import javax.swing.JDialog;

public class Main {
    /**
     * Update the size of the dialog to ensure it will fit on the screen.
     * @param dialog The dialog to be resized.
     */
    public static void resizeDialogToScreen(JDialog dialog) {
        // Get the maximum window size to account for taskbars etc
        Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

        final Dimension dialogSize = dialog.getSize();

        if (dialogSize.height > screenBounds.height) {
            dialogSize.height = screenBounds.height;
        }

        if (dialogSize.width > screenBounds.width) {
            dialogSize.width = screenBounds.width;
        }
        dialog.setSize(dialogSize);
    }
}

Related

  1. messageDialog(String string, JDialog parentDialog)
  2. openDialog(final JDialog dialog)
  3. poseInsideScreen(JDialog component)
  4. positionDialogInContainer(JDialog dialog, Container frame, int horizontal, int vertical)
  5. renderDialog(JDialog thedialog, String szMessage, int noffsetx, int noffsety)
  6. rptaConfirmDialog(JDialog pJDialog, String pMensaje)
  7. runProgressBar(final Runnable runnable, final JDialog dialog)
  8. setActionsMenu(JDialog dialog, MenuElement menu)
  9. setCursorFree(JDialog dialog)