< prev index next >

src/java.desktop/share/classes/java/awt/Component.java

Print this page

        

@@ -2700,14 +2700,15 @@
         }
         return new Dimension(dim);
     }
 
     /**
-     * Sets the minimum size of this component to a constant
-     * value.  Subsequent calls to {@code getMinimumSize} will always
-     * return this value.  Setting the minimum size to {@code null}
-     * restores the default behavior.
+     * Sets the minimum size of this component to a constant value.
+     * If the value is greater than maximum size, then maximum size is also
+     * set to this value. Subsequent calls to {@code getMinimumSize} will 
+     * always return this value.
+     * Setting the minimum size to {@code null} restores the default behavior.
      *
      * @param minimumSize the new minimum size of this component
      * @see #getMinimumSize
      * @see #isMinimumSizeSet
      * @since 1.5

@@ -2717,17 +2718,28 @@
         // If the minimum size was set, use it as the old value, otherwise
         // use null to indicate we didn't previously have a set minimum
         // size.
         if (minSizeSet) {
             old = this.minSize;
-        }
-        else {
+        } else {
             old = null;
         }
         this.minSize = minimumSize;
         minSizeSet = (minimumSize != null);
         firePropertyChange("minimumSize", old, minimumSize);
+        if (isMaximumSizeSet() && minimumSize != null) {
+            Dimension lMaxSize = getMaximumSize();
+            if (lMaxSize.width < minimumSize.width) {
+                lMaxSize.width = minimumSize.width;
+            }
+            if ( lMaxSize.height < minimumSize.height) {
+                lMaxSize.height = minimumSize.height;
+            }
+            if (!maxSize.equals(lMaxSize)) {
+                setMaximumSize(lMaxSize);
+            }
+        }
     }
 
     /**
      * Returns whether or not {@code setMinimumSize} has been
      * invoked with a non-null value.

@@ -2773,14 +2785,15 @@
         }
         return new Dimension(dim);
     }
 
     /**
-     * Sets the maximum size of this component to a constant
-     * value.  Subsequent calls to {@code getMaximumSize} will always
-     * return this value.  Setting the maximum size to {@code null}
-     * restores the default behavior.
+     * Sets the maximum size of this component to a constant value.
+     * If the value is smaller than minimum size, then maximum size is
+     * set to minimum size. Subsequent calls to {@code getMaximumSize}
+     * will return this or corrected value.
+     * Setting the maximum size to {@code null} restores the default behavior.
      *
      * @param maximumSize a {@code Dimension} containing the
      *          desired maximum allowable size
      * @see #getMaximumSize
      * @see #isMaximumSizeSet

@@ -2791,14 +2804,22 @@
         // use null to indicate we didn't previously have a set maximum
         // size.
         Dimension old;
         if (maxSizeSet) {
             old = this.maxSize;
-        }
-        else {
+        } else {
             old = null;
         }
+        if (isMinimumSizeSet() && maximumSize != null) {
+            Dimension lMinSize = getMinimumSize();
+            if (maximumSize.width < lMinSize.width) {
+                maximumSize.width = lMinSize.width;
+            }
+            if (maximumSize.height < lMinSize.height) {
+                maximumSize.height = lMinSize.height;
+            }
+        }
         this.maxSize = maximumSize;
         maxSizeSet = (maximumSize != null);
         firePropertyChange("maximumSize", old, maximumSize);
     }
 
< prev index next >