Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the background of a jspinner using the nimbus laf?

I'm fairly confident that I have done my research before coming to you for help, but it's possible I have overlooked something.

I'm writing a java UI using the Nimbus l-a-f. I wish to change the background colour of a JSpinner on state-change, ie, when either the up or down button is pressed the background colour of the textfield within the jspinner changes colour to signify that the value has been altered.

I am aware this is possible using OTHER lookandfeels but not as easy with Nimbus, eg: ((JSpinner.NumberEditor)jSpinner1.getEditor()).getTextField().setBackground(color.yellow);

I have also looked into actually changing the colour theme of the UI manager, but I only want to change the colour when an action occurs, not just overall by default. here or here

Is this at all possible and where do I start?

Failing this, I was hoping to just change a button's colour: jButton.setBackground(Color.yellow);

This is easy enough but since the default colour is a painted gradient, how do I change it back to that?

Really hope someone out there knows or can help.

Much appreciated in advance!

like image 921
Daryl Avatar asked Nov 14 '22 15:11

Daryl


1 Answers

Yes, it is possible. See this example (i.e. SpinnerDemo4) from The Java Tutorials for more detail. And yes, I did set the LaF to Nimbus when testing the code therein.

like image 155
mre Avatar answered Dec 23 '22 13:12

mre