Setting new TableModels to a JTable

I have a JTable that is contained with in a split pane.  On the right of the splitPane I have a JList (which contains names of tables in a database).  When the user clicks on one of the table names in the JList I want to go to the database get the info and load it into into the JTable.  What I am doing now is creating a new TableModel everytime and setting it to the JTable.  I am having some problems with the custom MouseListeners because they do not work with the new TableModel.  

1.)  Is this the correct way to do this?

2.)  If so is there a way to remove just the mouseListener I want and then register a new one with the new TableModel?

Thanks for your help!!
kassidy2010Asked:
Who is Participating?
 
objectsCommented:
> 1.)  Is this the correct way to do this?

yes

> 2.)  If so is there a way to remove just the mouseListener I want and then register a new one with the new TableModel?

No need, the MouseListener's are attached to the table, *not* the model
Problem may be with the mouse listener itself, make sure they are accessing the model from table ie. the current table model and not an old one.

0
 
CEHJCommented:
You can reuse the TableModel. Make you load the JTable in a separate thread
0
 
CEHJCommented:
Typo

Make you=Make sure you
0
 
hoomanvCommented:
> custom MouseListeners do not work with the new TableModel

you mean
jTable.addMouseListener(new MyMouseListener());
and then
jTable.setModel(new MyModel());
causes the previously registered mouse listener to stop listening ? seems irrelevant
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.