Here you can find the source of restrictWindowMinimumSize(final Window wnd, final Dimension minSize)
Parameter | Description |
---|---|
wnd | Window which size should be restricted. |
minSize | The minimum allowed size for the window. |
public static void restrictWindowMinimumSize(final Window wnd, final Dimension minSize)
//package com.java2s; /*//from www . jav a2s .c o m * Swing Explorer. Tool for developers exploring Java/Swing-based application internals. * Copyright (C) 2012, Maxim Zakharenkov * * 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.Component; import java.awt.Dimension; import java.awt.Window; import java.awt.event.ComponentEvent; import javax.swing.JInternalFrame; public class Main { /** * Adds listener to window that ensures that * the window is not resized less then specified size. * In case if it is resized anyway it restores the * minimal size. * * @param wnd Window which size should be restricted. * @param minSize The minimum allowed size for the window. */ public static void restrictWindowMinimumSize(final Window wnd, final Dimension minSize) { restrictMinimumSizeImpl(wnd, minSize); } /** * Adds listener to internal frame that ensures that * the frame is not resized less then specified size. * In case if it is resized anyway it restores the * minimal size. * * @param frame Frame which size should be restricted. * @param minSize The minimum allowed size for the window. */ public static void restrictWindowMinimumSize(final JInternalFrame frame, final Dimension minSize) { restrictMinimumSizeImpl(frame, minSize); } private static void restrictMinimumSizeImpl(final Component component, final Dimension minSize) { // Ensure that window has normal size before resizing event Dimension curSize = component.getSize(); if (curSize.width < minSize.width || curSize.height < minSize.height) { component.setSize(minSize); } // Adding listener. If added after size settings - will not be added if // one of arguments is NULL. component.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(ComponentEvent e) { Dimension curSize = component.getSize(); if (curSize.width < minSize.width || curSize.height < minSize.height) { Dimension newSize = new Dimension(Math.max(minSize.width, curSize.width), Math.max(minSize.height, curSize.height)); component.setSize(newSize); } } }); } }