This patch (committed) fixes a problem that shows up when trying to run the LiquidLookAndFeel [1] on GNU Classpath where an exception is thrown because the JMenuItem button model hasn't been initialised at the point that the UI delegate is set:

2006-09-19  David Gilbert  <[EMAIL PROTECTED]>

        * javax/swing/AbstractButton.java
        (AbstractButton): Don't call updateUI(),
        * javax/swing/JButton.java
        (JButton(String, Icon)): Call setModel() before init(),
        * javax/swing/JMenuItem.java
        (JMenuItem()): Delegate to another constructor,
        (JMenuItem(Icon)): Likewise,
        (JMenuItem(Action)): Set model,
        (JMenuItem(String, Icon)): Likewise,
        * javax/swing/JToggleButton.java
        (init): Call setModel() before init().

I have some Mauve tests to cover these changes.

Regards,

Dave

[1] https://liquidlnf.dev.java.net/
Index: javax/swing/AbstractButton.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/AbstractButton.java,v
retrieving revision 1.67
diff -u -r1.67 AbstractButton.java
--- javax/swing/AbstractButton.java     12 Sep 2006 09:02:05 -0000      1.67
+++ javax/swing/AbstractButton.java     19 Sep 2006 14:07:06 -0000
@@ -908,7 +908,6 @@
     // hard-coded here and the 'Button.iconTextGap' setting in the 
     // UI defaults is ignored, at least by the MetalLookAndFeel
     iconTextGap = 4;
-    updateUI();
   }
 
   /**
@@ -969,6 +968,8 @@
 
     if (icon != null)
       default_icon = icon;
+    
+    updateUI();
  }
  
   /**
Index: javax/swing/JButton.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JButton.java,v
retrieving revision 1.26
diff -u -r1.26 JButton.java
--- javax/swing/JButton.java    19 Apr 2006 21:00:17 -0000      1.26
+++ javax/swing/JButton.java    19 Sep 2006 14:07:06 -0000
@@ -132,8 +132,8 @@
   public JButton(String text, Icon icon)
   {
     super();
-    init(text, icon);
     setModel(new DefaultButtonModel());
+    init(text, icon);
     defaultCapable = true;
   }
 
Index: javax/swing/JMenuItem.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JMenuItem.java,v
retrieving revision 1.33
diff -u -r1.33 JMenuItem.java
--- javax/swing/JMenuItem.java  23 Aug 2006 22:03:23 -0000      1.33
+++ javax/swing/JMenuItem.java  19 Sep 2006 14:07:08 -0000
@@ -81,8 +81,7 @@
    */
   public JMenuItem()
   {
-    super();
-    init(null, null);
+    this(null, null);
   }
 
   /**
@@ -94,8 +93,7 @@
   {
     // FIXME: The requestedFocusEnabled property should
     // be set to false, when only icon is set for menu item.
-    super();
-    init(null, icon);
+    this(null, icon);
   }
 
   /**
@@ -117,6 +115,7 @@
   {
     super();
     super.setAction(action);
+    setModel(new DefaultButtonModel());
     init(null, null);
     if (action != null)
       {
@@ -148,6 +147,7 @@
   public JMenuItem(String text, Icon icon)
   {
     super();
+    setModel(new DefaultButtonModel());
     init(text, icon);
   }
 
@@ -174,7 +174,6 @@
   protected void init(String text, Icon icon)
   {
     super.init(text, icon);
-    setModel(new DefaultButtonModel());
 
     // Initializes properties for this menu item, that are different
     // from Abstract button properties. 
Index: javax/swing/JToggleButton.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JToggleButton.java,v
retrieving revision 1.28
diff -u -r1.28 JToggleButton.java
--- javax/swing/JToggleButton.java      10 Mar 2006 16:50:49 -0000      1.28
+++ javax/swing/JToggleButton.java      19 Sep 2006 14:07:08 -0000
@@ -1,5 +1,5 @@
 /* JToggleButton.java -- 
-   Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005, 2006,  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -291,9 +291,8 @@
   public JToggleButton (String text, Icon icon, boolean selected) 
   {
     super();
+    setModel(new ToggleButtonModel());  
     init(text, icon);
-
-    setModel(new ToggleButtonModel()); 
     model.setSelected(selected);
     setAlignmentX(LEFT_ALIGNMENT);
   }

Reply via email to