Just like with the MetalButtonUI, I fixed the conditions under which the MetalToggleButtonUI paints a gradient: - the button's background must be a UIResource, otherwise the application expects the background to be painted. - the button is neither armed nor pressed. in these cases the button is painted in the pressed state, which is not gradiented - the button must be contentAreaFilled. this is normally mapped to opaque and makes no difference. however, user code can theoretically override the isContentAreaFilled to not forward to opaque. - the button must be enabled. otherwise it is painted disabled, which is not gradiented
2006-03-28 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/plaf/metal/MetalButtonUI.java (update): Paint gradient only when the background color is not a UIResource and if the button is neither armed nor pressed and if the button is contentAreaFilled. /Roman -- “Improvement makes straight roads, but the crooked roads, without Improvement, are roads of Genius.” - William Blake
Index: javax/swing/plaf/metal/MetalToggleButtonUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java,v retrieving revision 1.9 diff -u -1 -0 -r1.9 MetalToggleButtonUI.java --- javax/swing/plaf/metal/MetalToggleButtonUI.java 10 Mar 2006 22:40:47 -0000 1.9 +++ javax/swing/plaf/metal/MetalToggleButtonUI.java 28 Mar 2006 21:49:59 -0000 @@ -38,26 +38,28 @@ package javax.swing.plaf.metal; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.AbstractButton; +import javax.swing.ButtonModel; import javax.swing.JComponent; import javax.swing.JToggleButton; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicButtonUI; import javax.swing.plaf.basic.BasicToggleButtonUI; /** * A UI delegate for the [EMAIL PROTECTED] JToggleButton} component. */ public class MetalToggleButtonUI extends BasicToggleButtonUI { @@ -202,21 +204,26 @@ g.setColor(saved); } /** * If the property <code>ToggleButton.gradient</code> is set, then a gradient * is painted as background, otherwise the normal superclass behaviour is * called. */ public void update(Graphics g, JComponent c) { - if (c.isOpaque() && UIManager.get(getPropertyPrefix() + "gradient") != null) + AbstractButton b = (AbstractButton) c; + ButtonModel m = b.getModel(); + if (b.getBackground() instanceof UIResource + && b.isContentAreaFilled() + && b.isEnabled() && ! m.isArmed() && ! m.isPressed() + && UIManager.get(getPropertyPrefix() + "gradient") != null) { MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(), SwingConstants.VERTICAL, getPropertyPrefix() + "gradient"); paint(g, c); } else super.update(g, c); }
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil