Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and Model

 
S Raman
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic