IntelliJ Java IDE
The moose likes Swing / AWT / SWT / JFace and the fly likes JSpinner - disabled foreground color Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "JSpinner - disabled foreground color" Watch "JSpinner - disabled foreground color" New topic
Author

JSpinner - disabled foreground color

Kurt Peters
Greenhorn

Joined: Apr 22, 2009
Posts: 17
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
Rancher

Joined: Jun 09, 2003
Posts: 4041
Kurt Peters
Greenhorn

Joined: Apr 22, 2009
Posts: 17
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
Rancher

Joined: Jun 09, 2003
Posts: 4041
> 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"
 
 
subject: JSpinner - disabled foreground color
 
Threads others viewed
Getting a couple errors on scribble applet
JSpinner keyboard input event
how can i set the XOR mode of a JTextComponent
TableCellRenderer performance tuning problem
Override the gray text generated from disabled="true"
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture