• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSpinner - disabled foreground color  RSS feed

 
Kurt Peters
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSpinner that I want to be able to optionally disable spinner input, but...

I still want to use the editor part as a display by slaving it to something else. That is working, but when I do a "setEnable(false)" the display turns gray.

I've tried significant options to make it NOT be gray, but can't get it to behave. I've defined
my own Jspinner class with


but that only changes the foreground in "NON DISABLED" mode. I need the foreground to change in DISABLED mode as well.

Any ideas?

As I said, I have my own JSpinner class now so modifying that isn't an issue.

Regards,
Kurt
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Kurt Peters
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that worked. How would a mere mortal figure that one out from the documentation?

My change foreground code is now:

I'm thinking it would get the color from the enabled one?
Kurt
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I'm thinking it would get the color from the enabled one?

UIManager.getColor("TextField.foreground") gets whatever the 'default' is,
so should match the enabled one, but you can specify any color e.g.
tf.setDisabledTextColor(Color.YELLOW);

there is no real need to put it in the overridden setForeground().
on it's own in the constructor will do - once set, stays that value until changed,
regardless of whether the spinner is disabled/re-enabled/disabled again

[edit]
forgot this bit
> Thanks, that worked. How would a mere mortal figure that one out from the documentation?

there are a huge number of methods in the JTextComponent api, so most of your document reading
in regard to text components (textfield, textArea etc) should be directed to "methods inherited from JTextComponent"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!