• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I change the back/foreground color of a disabled JComboBox?

 
Jose Roel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I need change the background and foreground color when a JComboBox is disabled, is it possible?

Thanks in advance.
 
Dragan Stankovic
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you can, try:



For a complete list of properties you can change in this way try:

http://safari.oreilly.com/0596004087/jswing2-APP-A
[ November 05, 2008: Message edited by: Dragan Stankovic ]
 
Jose Roel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but this has a problem. I only want to change some JComboBox (my JComboBoxCustom) of the aplication, not all.

Thanks for your time.
 
Akhshay Ray
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then use a renderer
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make the comboBox editable
get the editor component (textfield)
use textfield's setDisabledTextColor (inherited from JTextComponent)
 
Jose Roel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried

cbox.setEditable(true);
BasicComboBoxEditor editor = (BasicComboBoxEditor)cbox.getEditor();
cbox.setEnabled(false);
editor.getEditorComponent().setBackground(Color.green); editor.getEditorComponent().setForeground(Color.yellow);

but doesn't work...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic