jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes How do I disable some of the elements in my 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 "How do I disable some of the elements in my JComboBox?" Watch "How do I disable some of the elements in my JComboBox?" New topic
Author

How do I disable some of the elements in my JComboBox?

Amit Rosner
Greenhorn

Joined: Dec 03, 2001
Posts: 22
Hi,

I want to enable/disable items in my JComboBox selectively.
How do I do that?

Amit.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
1. Define your own ComboBoxModel. You could subclass DefaultComboBox model, adding methods isItemDisabled and setItemDisabled, and override method setSelectedItem.
2. You probably want disabled items rendered differently. Define your own ListCellRenderer.


There is no emoticon for what I am feeling!
Amit Rosner
Greenhorn

Joined: Dec 03, 2001
Posts: 22
Hi,

I'm having some difficulties with your suggestions...
Can you please give me a working example?

Thanks in advance,
Amit.
[ January 24, 2006: Message edited by: Amit Rosner ]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
My hints were explicit, and here at JavaRanch the emphasis is on teaching folks to fish, not giving them a fish, or something like that...

When you tried to follow the suggestions what went wrong?
 
Consider Paul's rocket mass heater.
 
subject: How do I disable some of the elements in my JComboBox?