• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Real time biding of JComboBox with Table

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I hope I am posting this question in right section.
In my swing application, I wanted bind JComboBox to Measurement_Unit table in database. I am using java docking, so multiple forms get loaded at the same time.
Now the problem is, When I change the content of Measurement_Unit table in one form, it doesnt get reflected in other form containing JComboBox until and unless I restart the application or reload the form.

I wanted to know which listener I use to listen the changes in list bound to JComboBox and which type of even I should fire when the data in first form is changed?

Thanks in advance..!!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a TableModelListener.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I change the content of Measurement_Unit table in one form, it doesnt get reflected in other form containing JComboBox until and unless I restart the application or reload the form.



Share the model of the combo box across all forms.

 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot to both Rob for your response.
@ Rob Prime: Its not swing table, so I cannot add TableModelListener.

@Rob Camick: I think this solution will work, but the problem is, i'll have to create a static object of model, right?

I am looking for a ActionEvent, and ActionListener model for this problem. Like, when the object is added or removed, some ActionEvent should get fired, all the corresponding ComboBox objects should update themselves after listening to this event. Can somebody suggest me a solution for this.
(I am sorry, I don't have much idea about ActionEvent and ActionListener, so a detailed explanation will be very much helpful, or may be some link for beginners.)
 
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
No, you most emphatically DO NOT have to "create a static object of model". The way to share the model is simplyIf the combo boxes are in different classes/scopes you will need a method that sets the combo's model, and pass it the shared model as a parameter.

If all you want to do is keep all the JComboBoxes in sync, an ActionListener isn't required for that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic