Hi,

Came across a problem when painting a JComboBox with null or empty items
in it; patch is attached.

It's a bit of a workaround, but I think it's good enough (it's a rare
case, so it's not worth hacking into the higher Component-level methods
that the ComboBox inherits).

Corresponding Mauve testcase is also being submitted on that list.

Francis

Index: javax/swing/plaf/basic/BasicComboBoxRenderer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboBoxRenderer.java,v
retrieving revision 1.9
diff -u -r1.9 BasicComboBoxRenderer.java
--- javax/swing/plaf/basic/BasicComboBoxRenderer.java	17 Mar 2006 15:18:24 -0000	1.9
+++ javax/swing/plaf/basic/BasicComboBoxRenderer.java	8 Jun 2006 18:47:03 -0000
@@ -75,12 +75,24 @@
 
   /**
    * Returns preferredSize of the renderer
-   *
+   * 
    * @return preferredSize of the renderer
    */
   public Dimension getPreferredSize()
   {
-    return super.getPreferredSize();
+    if (this.getText() != null && ! this.getText().equals(""))
+      return super.getPreferredSize();
+    else
+      {
+        // If the combo box option's text is empty or null, it won't size
+        // properly (ie, it'll be way too short)... so we throw in a dummy
+        // space to trick the superclass's sizing methods.
+        String oldText = this.getText();
+        this.setText(" ");
+        Dimension d = super.getPreferredSize();
+        this.setText(oldText);
+        return d;
+      }
   }
 
   /**

Reply via email to