classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: fix javax.swing.plaf.metal.MetalComboBoxUI


From: Roman Kennke
Subject: [cp-patches] FYI: fix javax.swing.plaf.metal.MetalComboBoxUI
Date: Thu, 19 May 2005 13:45:41 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204

MetalComboBoxUI instances must not be shared between multiple JComboBox instances. I committed the attached patch that fixes this.

2005-05-19  Roman Kennke  <address@hidden>

       * javax/swing/plaf/metal/MetalComboBoxUI.java
       (createUI): Do not share instances of this UI class between
       different JComboBoxes.

/Roman

Index: javax/swing/plaf/metal/MetalComboBoxUI.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalComboBoxUI.java,v
retrieving revision 1.1
diff -u -r1.1 MetalComboBoxUI.java
--- javax/swing/plaf/metal/MetalComboBoxUI.java 14 Apr 2005 18:00:46 -0000      
1.1
+++ javax/swing/plaf/metal/MetalComboBoxUI.java 19 May 2005 11:40:50 -0000
@@ -38,6 +38,8 @@
 
 package javax.swing.plaf.metal;
 
+import java.util.HashMap;
+
 import javax.swing.JComponent;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicComboBoxUI;
@@ -46,9 +48,8 @@
   extends BasicComboBoxUI
 {
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
-  /** The shared UI instance for JComboBoxes. */
-  private static MetalComboBoxUI instance = null;
+  /** The UI instances for JComboBoxes. */
+  private static HashMap instances = null;
 
   /**
    * Constructs a new instance of MetalComboBoxUI.
@@ -67,8 +68,19 @@
    */
   public static ComponentUI createUI(JComponent component)
   {
-    if (instance == null)
-      instance = new MetalComboBoxUI();
+    if (instances == null)
+      instances = new HashMap();
+
+    Object o = instances.get(component);
+    MetalComboBoxUI instance;
+    if (o == null)
+      {
+       instance = new MetalComboBoxUI();
+       instances.put(component, instance);
+      }
+    else
+      instance = (MetalComboBoxUI) o;
+
     return instance;
   }
 }

reply via email to

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