I was having a problem with an application that overrides setEnabled()
and isEnabled() in a JCheckBox in an weird way, which ended up in an
inconstisant state of JCheckBox.isEnabled() and
JCheckBox.getButtonModel().isEnabled(). This caused a difference in how
the JCheckBox is beeing painted (compared to the reference impl).
Although this is clearly a bug in the application, I check this fix in
anyway, since it makes the behaviour and the visual appearance more
consistent, even in the broken situations. (the 'behaviour' part relies
on the model, so should the painting do).

2006-05-05  Roman Kennke <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicRadioButtonUI.java
        (paint): Query the button model for it's state, not the
        button itself.

/Roman

Index: javax/swing/plaf/basic/BasicRadioButtonUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java,v
retrieving revision 1.15
diff -u -1 -0 -r1.15 BasicRadioButtonUI.java
--- javax/swing/plaf/basic/BasicRadioButtonUI.java	15 Nov 2005 20:32:46 -0000	1.15
+++ javax/swing/plaf/basic/BasicRadioButtonUI.java	5 May 2006 11:54:51 -0000
@@ -38,20 +38,21 @@
 
 package javax.swing.plaf.basic;
 
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 
 import javax.swing.AbstractButton;
+import javax.swing.ButtonModel;
 import javax.swing.Icon;
 import javax.swing.JComponent;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import javax.swing.plaf.ComponentUI;
 
 /**
  * The BasicLookAndFeel UI implementation for
  * [EMAIL PROTECTED] javax.swing.JRadioButton}s.
  */
@@ -135,45 +136,46 @@
     AbstractButton b = (AbstractButton) c;
 
     Rectangle tr = new Rectangle();
     Rectangle ir = new Rectangle();
     Rectangle vr = new Rectangle();
 
     Font f = c.getFont();
 
     g.setFont(f);
 
+    ButtonModel m = b.getModel();
     Icon currentIcon = null;
-    if (b.isSelected() && b.isEnabled())
+    if (m.isSelected() && m.isEnabled())
       currentIcon = b.getSelectedIcon();
-    else if (!b.isSelected() && b.isEnabled())
+    else if (! m.isSelected() && m.isEnabled())
       currentIcon = b.getIcon();
-    else if (b.isSelected() && !b.isEnabled())
+    else if (m.isSelected() && ! m.isEnabled())
       currentIcon = b.getDisabledSelectedIcon();
-    else // (!b.isSelected() && !b.isEnabled())
+    else // (!m.isSelected() && ! m.isEnabled())
       currentIcon = b.getDisabledIcon();
 
     SwingUtilities.calculateInnerArea(b, vr);
     String text = SwingUtilities.layoutCompoundLabel
       (c, g.getFontMetrics(f), b.getText(), currentIcon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        vr, ir, tr, b.getIconTextGap() + defaultTextShiftOffset);
     
     if (currentIcon != null)
       {
         currentIcon.paintIcon(c, g, ir.x, ir.y);
       }
     if (text != null)
       paintText(g, b, tr, text);
     // TODO: Figure out what is the size parameter?
-    if (b.hasFocus() && b.isFocusPainted() && b.isEnabled())
+    if (b.hasFocus() && b.isFocusPainted() && m.isEnabled())
       paintFocus(g, tr, null);
   }
 
   /**
    * Paints the focus indicator for JRadioButtons.
    *
    * @param g the graphics context
    * @param tr the rectangle for the text label
    * @param size the size (??)
    */

Reply via email to