aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Problem Updating JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Problem Updating JTable" Watch "Problem Updating JTable" New topic
Author

Problem Updating JTable

Joel Dubin
Greenhorn

Joined: Jul 30, 2001
Posts: 2
I am having difficulty updating my JTable from a JButton embedded in a panel separate from the panel holding the JTable. In other words, how do I communicate my data updates to the TableModel from a class separate from the JTable. My JButton takes the origin and destination airports from two JComboBox respectively and feeds the information into my criteriaFind() method. I don't want to create an inner class with the panel containing the JButton/JComboBox panel, since this would bloat my JTable panel code. I want to keep these two panels separate. When I embed a sample JButton, by itself, in my JTable panel, I can update the TableModel directly and update the JTable easily. Do I need to create some sort of Mediator, Facade or third class to communicate from my button/combo panel to the table?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
If you are not planning to expose the JTable to the other components in your app, then the only reasonable way to do it is to add methods in its container (panel) that update the table, which can be called by the other components.
I personally had a Client (JFrame), which contained a tabbed pane with two panels FlightSearchPanel, and FlightInfoPanel. The Client acted as the Mediator of these two and some other components. So when the search button is pressed, an anonymous ActionListener implemented in Client would perform the search, and call a method setFlights() in FlightSearchPanel, which was there delegated to the actual TableModel.
I hope I was clear enough and you got my idea... Hope this helps!!!
Benjam´┐Żn
Joel Dubin
Greenhorn

Joined: Jul 30, 2001
Posts: 2
I just figured it out based on your reply!! What I did was use the JFrame, which holds instances of all the GUI objects -- the combo boxes/button panel and the table panel -- as the Mediator. I created an instance of my table model in the JFrame and then passed that instance as a parameter to each of the instantiations of the two panels. In the panels themselves, I passed the table model as a parameter in the constructor of the panels. For the panel holding the table, I assigned the parameter value to the model instance that called my updating method in the table model. I hope this makes sense. In any case, it worked and I was able to keep all my panels and frame as separate, free-standing classes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem Updating JTable