I have a JButton in my Nimbus L&F setting with MouseListener. I was able to change the text color when mouse enter but cannot change the color back or to another color when mouse exit. From print out I am sure the mouseExit is called.
Anybody can help me figure out why?
I am thinking after the mouseEntered() is called, the btn_f is not Nimbus L&F anymore. I don't know my guess makes sense or not.
The code likes this:
@Override
public void mouseEntered(MouseEvent e) {
Object resource = e.getSource();
if(resource == btn_f)
{
System.out.println("@@@@@@@@@@@@@====btn_f is enterred");
UIDefaults defaults = new UIDefaults();
defaults.put("Button.textForeground", Color.BLUE);
btn_f.putClientProperty("Nimbus.Overrides", defaults);
//btn_f.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
//SwingUtilities.updateComponentTreeUI(btn_f);
}
}
@Override
public void mouseExited(MouseEvent e) {
Object resource = e.getSource();
if(resource == btn_f)
{
System.out.println("@@@@@@@@@@@@@====btn_f is exited");
UIDefaults defaults = new UIDefaults();
defaults.put("Button.textForeground", Color.RED);
btn_f.putClientProperty("Nimbus.Overrides", defaults);
//btn_f.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
//SwingUtilities.updateComponentTreeUI(btn_f);
}
}