File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Amit Rosner
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Amit.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amit Rosner
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic