I have a custom ButtonUI class that paints the button. Before drawing the text, the paint method checks whether the button has been set a custom color in order to use that instead of UIDefaults#get("Button.foreground").
if ((b.getForeground() != null)) {
colText = b.getForeground();
}
Having a look into the java.awt.Component class yields a problem:
public Color getForeground() {
Color foreground = this.foreground;
if (foreground != null) {
return foreground;
}
Container parent = this.parent;
return (parent != null) ? parent.getForeground() : null;
}
So checking the button's getForeground() against null doesn't help that much as it will return the foreground color for the component the button is placed on.
Question is: How do I check whether the button has explicitly been set a custom foreground color?
Putting a PropertyChangedListener on the button might be a solution, but I somehow think there must be a simpler way.