wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Real time biding of JComboBox with Table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Real time biding of JComboBox with Table" Watch "Real time biding of JComboBox with Table" New topic
Author

Real time biding of JComboBox with Table

Mahesh Kedari
Ranch Hand

Joined: Nov 28, 2009
Posts: 111
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..!!

Regards,
Mahesh Kedari - Fidus Technologies Ltd.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Use a TableModelListener.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2090
    
    7
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

Joined: Nov 28, 2009
Posts: 111
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.)
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
 
Consider Paul's rocket mass heater.
 
subject: Real time biding of JComboBox with Table
 
Similar Threads
problem in JComboBox
Caching of Query Results
how to store datecombobox in an arraylist of type combobox
JComboBox with enum
getValueAt in JTable