Here you can find the source of resizeDialogToScreen(JDialog dialog)
Parameter | Description |
---|---|
dialog | The dialog to be resized. |
public static void resizeDialogToScreen(JDialog dialog)
//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); } }