• 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

Updating a JCombo Box at run time

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
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 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)
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a tutorial linked from the API for JComboBox. Have you gone through it?
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic