• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating a JCombo Box at run time

 
Umesh Pandey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Umesh Pandey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a tutorial linked from the API for JComboBox. Have you gone through it?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the Tutorial is a good place in general, since the OP has stated not to have experience with Swing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic