classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: preferredSize in JComponent


From: Roman Kennke
Subject: [cp-patches] FYI: preferredSize in JComponent
Date: Mon, 20 Jun 2005 16:40:16 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

We already had two fixes in the last weeks about this issue. The problem was that preferredSize must not be less than minimumSize. The solution so far has been to adjust preferredSize when minimumSize is set. This has the sideeffect that getPreferredSize() is called too early or (after Marks fix) that the preferredSize of the ComponentUI is not recognized. This new fix solves the problem at the other end: when calling getPreferredSize (not on setMinimumSize) we check if it is less than minimumSize and adjust if necessary.

2005-06-20  Roman Kennke  <address@hidden>

   * javax/swing/JComponent.java
   (getPreferredSize): Make sure that preferredSize is greater than
   minimumSize.
   (setMinimumSize): Removed hack to adjust preferredSize. This is moved
   into the method getPreferredSize().

/Roman

Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.44
diff -u -r1.44 JComponent.java
--- javax/swing/JComponent.java 20 Jun 2005 13:27:59 -0000      1.44
+++ javax/swing/JComponent.java 20 Jun 2005 13:54:09 -0000
@@ -1024,17 +1024,25 @@
    */
   public Dimension getPreferredSize()
   {
+    Dimension prefSize = null;
     if (preferredSize != null)
-      return preferredSize;
+      prefSize = preferredSize;

     if (ui != null)
       {
         Dimension s = ui.getPreferredSize(this);
         if (s != null)
-          return s;
+          prefSize = s;
       }
-    Dimension p = super.getPreferredSize();
-    return p;
+    if (prefSize == null)
+      prefSize = super.getPreferredSize();
+    // make sure that prefSize is not smaller than minSize
+    if (minimumSize != null && prefSize != null
+        && (minimumSize.width > prefSize.width
+            || minimumSize.height > prefSize.height))
+        prefSize = new Dimension(Math.max(minimumSize.width, prefSize.width),
+                                 Math.max(minimumSize.height, 
prefSize.height));
+    return prefSize;
   }

   /**
@@ -2063,22 +2071,6 @@
     firePropertyChange("minimumSize", oldMinimumSize, minimumSize);
     revalidate();
     repaint();
-
-    // adjust preferred and maximum size accordingly
-    if (preferredSize != null)
-      {
-       Dimension prefSize = getPreferredSize();
-       prefSize.width = Math.max(prefSize.width, minimumSize.width);
-       prefSize.height = Math.max(prefSize.height, minimumSize.height);
-       setPreferredSize(prefSize);
-      }
-    if (maximumSize != null)
-      {
-       Dimension maxSize = getMaximumSize();
-       maxSize.width = Math.max(maxSize.width, minimumSize.width);
-       maxSize.height = Math.max(maxSize.height, minimumSize.height);
-       setMaximumSize(maxSize);
-      }
   }

   /**

reply via email to

[Prev in Thread] Current Thread [Next in Thread]