This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes 2 ComboBox's 1 Set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "2 ComboBox Watch "2 ComboBox New topic
Author

2 ComboBox's 1 Set

Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Hey all,

I intend having a search where the user can search on two entitys in the database. eg-color and size, shape and sound, height and speed etc. I will provide this functionality through two combo boxs. When the app loads, ComboBox 1's default selection will be color. ComboBox 2's default selection will be size.

So combo box 1 should have all the possible values except the value selected in combobox 2 (color,shape,sound,height,speed)
and combo box 2 should have all the possible values except the value selected in combobox 1 (size,shape,sound,height,speed)

All works great so far!

Next, I add an item listener to combo box 1 saying "if a value is selected in combobox 2, remove that value from combobox 1's set and add the previously selected value of combobox 2, back into combo box 1's set of possible values."

Similarly, I add an item listener to combo box 2 saying "if a value is selected in combobox 1, remove that value from combobox 2's set and add the previously selected value of combobox 1, back into combo box 2's set of possible values."

This works superbly!

Until...

User selects their desired choice in combobox1 (combobox2's values immediatley update). The user then selects their desired choice in combobox2 (combobox1's values immediatley update ).

If you are still reading do you have any ideas?

Thanks,

G


OCPJP 6, OCMJD
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Glen Iris wrote:If you are still reading do you have any ideas?


excellent! Interestingly, I had already stopped reading when I saw this phrase!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Glen Iris wrote:User selects their desired choice in combobox1 (combobox2's values immediatley update). The user then selects their desired choice in combobox2 (combobox1's values immediatley update )


Well champ, isn't it the effect that you wanted? I think I didn't get your problem quite well... the problem is that you wanted the selected option in combo box 1 to stay selected after selecting an option in combo box 2?

Other than that, which assignment is this one? Back in my days, there were no such options... I think I'm getting old
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Roberto Perillo wrote:
Glen Iris wrote:User selects their desired choice in combobox1 (combobox2's values immediatley update). The user then selects their desired choice in combobox2 (combobox1's values immediatley update )


the problem is that you wanted the selected option in combo box 1 to stay selected after selecting an option in combo box 2?(


Thats it in a nutshell Roberto. Its the bodgitt and scarper. The user must be able to search on the name, the location or both. I was trying to allow the user to search on any two db parameters. I guess Im over complicating it.

Any ideas on how to allow the user this functionality. I guess radio buttons, or two text fields (one for name, one for location).

G
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

Glen Iris wrote:two text fields (one for name, one for location).

That's exactly what I did. One text field for name and another for location. If nothing is entered, all (valid) records are returned. If they fill both, all records with exactly matching name and location are returned. If they fill only one of the text fields, all records with exactly matching name or location are returned. Very easy to implement, easy to use and very intuitive for a user.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

I guess I was trying to be too clever for my own good. Thanks Roel.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

Never a good idea Always think KISS when developing an application It saved me already lots of time and many
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 2 ComboBox's 1 Set
 
Similar Threads
How to generate Action on JComboBox click
Event Handling
Netbeans GUI Code Doubt
JTables
JTable selected row problem