File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I change the back/foreground color of a disabled JComboBox?
 
Similar Threads
Disabled components
JComboBox: Opaque problem
setting foreground of a disabled text field
How to make JComboBox flash (red color)?
Why ComboBox.disabledForeground not work when set editable?