Hi, this patch fixes that customized background colors on JTextField instances are lost when someone switches the editable state[0].
2006-04-14 Robert Schuster <[EMAIL PROTECTED]>
* javax/swing/plaf/basic/BasicTextFieldUI.java:
(propertyChanged): Added note, change color only if current background
is a ColorUIResource instance.
cya
Robert
[0] - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27147
Index: javax/swing/plaf/basic/BasicTextFieldUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTextFieldUI.java,v
retrieving revision 1.6
diff -u -r1.6 BasicTextFieldUI.java
--- javax/swing/plaf/basic/BasicTextFieldUI.java 14 Nov 2005 12:16:43 -0000 1.6
+++ javax/swing/plaf/basic/BasicTextFieldUI.java 14 Apr 2006 16:51:34 -0000
@@ -38,10 +38,12 @@
package javax.swing.plaf.basic;
+import java.awt.Color;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent;
import javax.swing.UIDefaults;
+import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.ComponentUI;
import javax.swing.text.Element;
import javax.swing.text.FieldView;
@@ -83,6 +85,9 @@
* Receives notification whenever one of the text component's bound
* properties changes. Here we check for the editable and enabled
* properties and adjust the background color accordingly.
+ *
+ * <p>The colors are only changed if they are not a
+ * <code>ColorUIResource</code>.</p>
*
* @param event the property change event
*/
@@ -91,10 +96,11 @@
if (event.getPropertyName().equals("editable"))
{
boolean editable = ((Boolean) event.getNewValue()).booleanValue();
- if (editable)
- textComponent.setBackground(background);
- else
- textComponent.setBackground(inactiveBackground);
+
+ // Changing the color only if the current background is an instance of
+ // ColorUIResource is the behavior of the RI.
+ if (textComponent.getBackground() instanceof ColorUIResource)
+ textComponent.setBackground(editable ? background : inactiveBackground);
}
}
}
signature.asc
Description: OpenPGP digital signature
