This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Disabling Combo box

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> I am looking something similar to ButtonGroup

what happened when you tried it?

[edit]

oops, was thinking of checkBox
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Darryl. Yeah, creating new class would be better idea and it can be used all across the project.
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic