I have a SWT Text field in my UI. If the text field contains an unusual value (as determined by my specific use case) I will set the background color red, to get the users attention. If the value (the text) of the text field changes to a normal value, I would like to set the background color back to default, but I don't see that this is possible.
Is it possible? Can I explicitly change the background color of a SWT Text widget back to default?
Try passing null
for the Color
argument to setBackground
:
text.setBackground(null);
I don't think there is a built-in method that gets the "original color". What I would suggest is keeping a field with the old value, and return it when needed:
class FlashingText extends Text{
//Enter needed ctors
private Color originalColor;
public void markForUser(){
originalColor = getBackground();
setBackground(Color.RED);
}
public void resetColor(){
setBackground(originalColor);
}
}
Notice this will work even if in the future you decide to change the Text's color for design purposes. Also notice giving an entity in your program an object is usually good design.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With