• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

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!!
0
kassidy2010
Asked:
kassidy2010
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now