Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Disabling Combo box  RSS feed

 
Rakesh shankar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am looking something similar to ButtonGroup (i.e on selection of one radio buttom, the others should be disabled) for Combo Box (i.e there are three comboBox, one selecting from one of the combo box the other two should be disabled automatically)
Please do let me know.

Thanks in advance..
Rakesh
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I am looking something similar to ButtonGroup

what happened when you tried it?

[edit]

oops, was thinking of checkBox
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no built in class which you can use for this. But it is quite easy to implement it yourself.
In pseudo code
1) Listen to selection events
2) On receiving a selection notification, figure out which combo box was the source
3) Disable the other two
 
Rakesh shankar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies.
Yes Maneesh, I am going to implement in the same fashion as you mentioned. But, my only concern with this approach is, if we add another combo box, we need to add that also while disabling, so it won't be generic.
So, I thought let me loop through all the components and check is it Combo box, if it is then disable.

Let me know, if there is any better approach than I mentioned above.

Thanks!
Rakesh
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to the question of a "better approach" would be
1) How many times do you think the number of combo boxes will change
2) Will your code be used by anyone else?

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
possibly another option is to create your own class of JComboBox and include
a static ArrayList. Whatever condition triggers the others to be disabled also loops
the arraylist disabling (or enabling) all non-getSource()
[edit]
and on creation, the comboBox is added to the arraylist
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:possibly another option is to create your own class of JComboBox and ...

Good idea, but I would avoid extending JComboBox and instead create a separate class ComboBoxGroup that mimicked ButtonGroup to provide the desired functionality. Adding each JComboBox to the group would add the requisite listener to the combo.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> create a separate class ComboBoxGroup that mimicked ButtonGroup

Good call, definitely a much better way to go, and relatively simple to implement.
 
Rakesh shankar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Darryl. Yeah, creating new class would be better idea and it can be used all across the project.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!