This fixes the initialization code for some buttons.

2005-09-30  Roman Kennke  <[EMAIL PROTECTED]>
        Fixes Bug #24115
        * javax/swing/AbstractButton.java
        (AbstractButton): Don't call init() from here. Moved some
        initialization code from init() to the constructor.
        (init): Moved most of the initialization code to the constructor.
        * javax/swing/JCheckBox.java
        (JCheckBox()): call this(..) instead of super(..). Don't call
init()         here, this is already performed by the
JToggleButton constructor.
        (JCheckBox(Action)): Don't call init() here, this is already
        performed by the JToggleButton constructor.
        (JCheckBox(Icon)): call this(..) instead of super(..). Don't call
        init() here, this is already performed by the JToggleButton
        constructor.
        (JCheckBox(Icon, boolean)): Likewise.
        (JCheckBox(String)): Likewise.
        (JCheckBox(String, boolean)): Likewise.
        (JCheckBox(String, Icon)): Likewise.
        (JCheckBox(String, Icon, boolean)): Don' call init here. This is
        already performed by the JToggleButton constructor. Set the
        correct defaults for horizontalAlignment and borderPainted
        properties here.
        * javax/swing/JRadioButton.java
        (JRadioButton(String, Icon, boolean)): Use acccessor methods
        instead of directly manipulating package private fields of
        AbstractButton.
        * javax/swing/JToggleButton.java
        (JToggleButton(String, Icon, boolean)): Set correct value for the
        alignmentX property.


/Roman
Index: javax/swing/AbstractButton.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/AbstractButton.java,v
retrieving revision 1.42
diff -u -r1.42 AbstractButton.java
--- javax/swing/AbstractButton.java	26 Jul 2005 15:30:54 -0000	1.42
+++ javax/swing/AbstractButton.java	30 Sep 2005 13:07:47 -0000
@@ -509,12 +509,37 @@
   }
 
   /**
-   * Creates a new AbstractButton object.
+   * Creates a new AbstractButton object. Subclasses should call the following
+   * sequence in their constructor in order to initialize the button correctly:
+   * <pre>
+   * super();
+   * init(text, icon);
+   * </pre>
+   *
+   * The [EMAIL PROTECTED] #init(String, Icon)} method is not called automatically by this
+   * constructor.
+   *
+   * @see [EMAIL PROTECTED] #init(String, Icon)}
    */
   public AbstractButton()
   {
-    init("", null);
     updateUI();
+
+    actionListener = createActionListener();
+    changeListener = createChangeListener();
+    itemListener = createItemListener();
+
+    horizontalAlignment = CENTER;
+    horizontalTextPosition = TRAILING;
+    verticalAlignment = CENTER;
+    verticalTextPosition = CENTER;
+    borderPainted = true;
+    contentAreaFilled = true;
+    focusPainted = true;
+    setFocusable(true);
+    setAlignmentX(CENTER_ALIGNMENT);
+    setAlignmentY(CENTER_ALIGNMENT);
+    setDisplayedMnemonicIndex(-1);
   }
 
   /**
@@ -569,25 +594,6 @@
 
     if (icon != null)
       default_icon = icon;
-
-    actionListener = createActionListener();
-    changeListener = createChangeListener();
-    itemListener = createItemListener();
-
-    horizontalAlignment = CENTER;
-    horizontalTextPosition = TRAILING;
-    verticalAlignment = CENTER;
-    verticalTextPosition = CENTER;
-    borderPainted = true;
-    contentAreaFilled = true;
-
-    focusPainted = true;
-    setFocusable(true);
-
-    setAlignmentX(LEFT_ALIGNMENT);
-    setAlignmentY(CENTER_ALIGNMENT);
-
-    setDisplayedMnemonicIndex(-1);    
  }
  
   /**
Index: javax/swing/JCheckBox.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JCheckBox.java,v
retrieving revision 1.17
diff -u -r1.17 JCheckBox.java
--- javax/swing/JCheckBox.java	12 Sep 2005 20:15:40 -0000	1.17
+++ javax/swing/JCheckBox.java	30 Sep 2005 13:07:47 -0000
@@ -97,50 +97,44 @@
   
   public JCheckBox()
   {
-    super();
-    init();
+    this(null, null, false);
   }
 
   public JCheckBox(Action action)
   {
     super(action);
-    init();
   }
 
   public JCheckBox(Icon icon)
   { 
-    super(icon);
-    init();
+    this(null, icon, false);
   }    
   
   public JCheckBox(Icon icon, boolean selected)
   { 
-    super(icon, selected);
-    init();
+    this(null, icon, selected);
   }    
   
   public JCheckBox(String text)
   {
-    super(text);
-    init();
+    this(text, null, false);
   }
       
   public JCheckBox(String text, boolean selected)
   {
-    super(text, selected);
-    init();
+    this(text, null, selected);
   }
       
   public JCheckBox(String text, Icon icon)
   {
-    super(text, icon);
-    init();
+    this(text, icon, false);
   }
 
   public JCheckBox(String text, Icon icon, boolean selected)
   {
     super(text, icon, selected);
-    init();
+    setHorizontalAlignment(LEADING);
+    setBorderPainted(false);
   }
 
   /**
Index: javax/swing/JRadioButton.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JRadioButton.java,v
retrieving revision 1.16
diff -u -r1.16 JRadioButton.java
--- javax/swing/JRadioButton.java	13 Jul 2005 00:34:54 -0000	1.16
+++ javax/swing/JRadioButton.java	30 Sep 2005 13:07:48 -0000
@@ -192,8 +192,8 @@
   public JRadioButton(String text, Icon icon, boolean selected)
   {
     super(text, icon, selected);
-    borderPainted = false;
-    contentAreaFilled = false;
+    setBorderPainted(false);
+    setHorizontalAlignment(LEADING);
   }
       
   /**
Index: javax/swing/JToggleButton.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JToggleButton.java,v
retrieving revision 1.25
diff -u -r1.25 JToggleButton.java
--- javax/swing/JToggleButton.java	22 Jul 2005 12:34:35 -0000	1.25
+++ javax/swing/JToggleButton.java	30 Sep 2005 13:07:48 -0000
@@ -276,6 +276,7 @@
 
     setModel(new ToggleButtonModel());	
     model.setSelected(selected);
+    setAlignmentX(LEFT_ALIGNMENT);
   }
 
   /**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to