This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Can I change the back/foreground color of a disabled JComboBox? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can I change the back/foreground color of a disabled JComboBox?" Watch "Can I change the back/foreground color of a disabled JComboBox?" New topic
Author

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

Jose Roel
Greenhorn

Joined: Nov 05, 2008
Posts: 3
Hi!

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

Thanks in advance.
Dragan Stankovic
Ranch Hand

Joined: Oct 14, 2008
Posts: 33
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 ]

http://www.expertaya.com
Jose Roel
Greenhorn

Joined: Nov 05, 2008
Posts: 3
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

Joined: Nov 21, 2003
Posts: 11
Then use a renderer
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
make the comboBox editable
get the editor component (textfield)
use textfield's setDisabledTextColor (inherited from JTextComponent)
Jose Roel
Greenhorn

Joined: Nov 05, 2008
Posts: 3
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...
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Can I change the back/foreground color of a disabled JComboBox?
 
It's not a secret anymore!