Setting new TableModels to a JTable

Posted on 2006-06-04
Last Modified: 2013-11-23
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!!
Question by:kassidy2010
    LVL 86

    Expert Comment

    You can reuse the TableModel. Make you load the JTable in a separate thread
    LVL 86

    Expert Comment


    Make you=Make sure you
    LVL 14

    Expert Comment

    > 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
    LVL 92

    Accepted Solution

    > 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?

    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.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now