File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 2265
    
    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: 2265
    
    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: 5265
    
  13

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: 5265
    
  13

Never a good idea Always think KISS when developing an application It saved me already lots of time and many
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 ComboBox's 1 Set