• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem updating my JTable based on a JList selection and a DefaultTableModel

 
Will Rogers
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a dialog app with a JList of employees on the left and a JTable of info about the employees on the right. When the user selects an employee from the JList, I want the data in the JTable to update to that of the selected users. The data for each employee uses the same TableModel, so all I need to do is update the rows. I've got the JList working with the ListSelectionListener, but I can't get it to update the table. My data model derives from DefaultTableModel and my main class implements ListSelectionListener and TableModelChangedListener. Here are my 2 "listener" functions:


In the main class's constructor, I call Model.addTableModelListener(this); to let the model know where to fire the events. What am I doing wrong? I never see the "Table Changed" message! TIA for any help.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't create a new model each time. Remove the old rows and add the new ones. You tied your model to your JTable once I assume. You don't need to create a new model again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!