jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes JTable and Model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and Model" Watch "JTable and Model" New topic
Author

JTable and Model

S Raman
Greenhorn

Joined: Mar 29, 2006
Posts: 16
Hi,

I am using JTable with MyModel which extends AbstractTableModel.

I am using this for searching Patients
My table contains firstname , lastname, and phoneno.
Data comes from Database.
My problem

Eventhough I clear data in the MyModel JTable shows previouss rows.
for new search.
ie everytime i make a new seach results of old search persist in my jtable and new result is added at the end

How do i clear the old rows.
I am calling MyModel.clearData() before adding the new resultVector to MyModel.

Another question is This I am doing in Search JButton action performed method. should i use SwingUtilities.Invoke method

what is the right way to call

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Originally posted by S Raman:
I am calling MyModel.clearData() before adding the new resultVector to MyModel.

What's the code for clearData()? It seems like that isn't actually clearing the data. Also, don't forget to fire an event that the table's contents have been changed. AbstractTableModel's fireTableDataChanged or fireTableRowsDeleted should suffice.
Another question is This I am doing in Search JButton action performed method. should i use SwingUtilities.Invoke method

Only if performing the search in a different thread.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
I'm no expert here, but would it be better to extend the default table model rather than the abstract one?
barron c. logan
Greenhorn

Joined: Nov 10, 2007
Posts: 1
Are you using setModel()? If you are creating a completely new Model why don't you reset the model:
table.setModel(newModel);

And about using SwingUtilities.invokeLater()

This utility effectively queues your Gui code to be run on the event dispatch thread.

Code that is executed from an ActionListener is already on the event dispatch thread.

The whole idea is to not block your main program thread... use SwingUtilities whenever your GUI code is not already on the event thread (ActionListener thread)

Hope this helps,

-Barron Logan
S Raman
Greenhorn

Joined: Mar 29, 2006
Posts: 16
Hi,

The Model stores data as m_vector
clearData calls m_vector.removeAllElements()

I check the size of model after that using m_vector.size and find it =0
yet the the table displays old data???

please help
thanks
S Raman
Greenhorn

Joined: Mar 29, 2006
Posts: 16
Hi,


I am actually receiving data from servlet into applet

I found even though the servlet side is sending only new objects
the client side is getting both new and old data
I have set

huc.setUseCaches(false);
huc.setDefaultUseCaches(false);
at applet

so where is the problem
I know this has become a applet servlet issue and i have to post applet servlet section

Thanks
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by S Raman:
The Model stores data as m_vector
clearData calls m_vector.removeAllElements()


That's not enough. As mentioned by Mr. Prime, you also must call fireTableDataChanged().

(Or you could call fireTableRowsDeleted() but in this case fireTableDataChanged() is simpler.)


bitguru blog
 
wood burning stoves
 
subject: JTable and Model