• Post Reply Bookmark Topic Watch Topic
  • New Topic

Disabled components

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I was wondering how I could change the background and foreground on a component that has been disabled.
I have run in to a couple of problems.
I have a JTextField disabled and I am able change the background color, but I can't seem to get the foreground color to change??
I also have a JComboBox that I have disabled. I can change the background to white, but the list part of it is still grey. How do I change the list part of the component and the foreground as well?
Any help would be appreciated!
Thanks.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setDisabledTextColor() from JTextComponent for the text field.
I'm not sure what you mean by the "list part" of the combo box. The little arrow/button thingie? I didn't think the actual list would pop up if the combo box was diabled.
Bill
 
David Garratt
Ranch Hand
Posts: 213
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your answer to the JTextfield problem was just what I needed. However is it possible to do the same sort of thing with the text element of a JSpinner ?

Thanks

Dave
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextField tf = ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField();
tf.setEnabled(false);
tf.setDisabledTextColor(UIManager.getColor("TextField.foreground"));
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!