5

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!

mre
  • 43,520
  • 33
  • 120
  • 170
Daryl
  • 203
  • 1
  • 2
  • 8

1 Answers1

1

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.

mre
  • 43,520
  • 33
  • 120
  • 170
  • Cheers for your response. I too have tried that demo & set the laf to nimbus, but it seems that all it is doing is replacing the JTextfield component with a JLabel, removing the visible number that I require. So I modified the code so that the Editor extended a JTextField instead, & inserted a line in the changelistener to change the background color, but the number still didn't display. So I also created a method to update the text to be displayed, but I still need this value to be manually editable by the user, which this process doesn't do. I dont understand why nimbus ignores SetBackground – Daryl Oct 27 '11 at 06:22