aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Updating a JCombo Box at run time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Updating a JCombo Box at run time" Watch "Updating a JCombo Box at run time" New topic
Author

Updating a JCombo Box at run time

Umesh Pandey
Greenhorn

Joined: Dec 27, 2012
Posts: 2
Hi,

I have three combo boxes, i am trying to update the Values of second combo box depending on the Value of First Combo box, Initially second and third JComobo Boxes are set not to be enabled. for ex: if 'A' is selected in first Combo Box then Second should get enabled and will display values related to 'A'.


I am having problem in enabling the Second Combo Box, I have attached Action Listener to both the Combo Box


Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> i am trying to update the Values of second combo box depending on the Value of First Combo box,

use the comboBox's model to do that
i.e. whatever's selected in combo1 creates a 'model' of items for display in combo2,
that model is then set as combo2's model.

for enabling/disabling have you thought of displaying no items in combo2 and combo3,
then setting their respective models, on selection of combo1 item.
(you would need to change from FlowLayout to perhaps GridLayout,
otherwise their sizes will look weird, and then change when models set)
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Umesh Pandey, please UseCodeTags (<- click) when posting your code. With proper indentation you will make your code a lot easier to read. I have added them for you this time.

And welcome to the Ranch!


The quieter you are, the more you are able to hear.
Umesh Pandey
Greenhorn

Joined: Dec 27, 2012
Posts: 2
Hi Michael,

Thanks for your suggestion, but can you please post some example how to create Combo Box Models. I am a beginner in this and has very little idea about Swing programming.

Regards,
Umesh
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

There's a tutorial linked from the API for JComboBox. Have you gone through it?


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Michael Dunn wrote:(you would need to change from FlowLayout to perhaps GridLayout,
otherwise their sizes will look weird, and then change when models set)


Or set an appropriate prototypeDisplayValue.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Actually, the Tutorial is a good place in general, since the OP has stated not to have experience with Swing.
 
Don't get me started about those stupid light bulbs.
 
subject: Updating a JCombo Box at run time