This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions on JTable

 
Walter Tang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

When I display the data from database, how can I discard the previous display in JTable. Because, when I do the search the second time, the results are appended to the previous results. That makes user really confused on the table. I hope I describe my problem acurately. Thanks a billion for your help

Walter
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on your table model class (I assume you have one).

You can create a new table model for your new data and then re-register it with the view JTable.setModel(myTableModel)

Or better,

you can write or use an existing setData type method that replaces the models collection of records, then fire a AbstractTableModel.fireDataChanged or whatever it's called.
 
Ed Green
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You could also try TableModel.setDataVector()?
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,Walter

If you want to use AbstractTableModel .All methods in the interface must be implemented.
Usually,you need to provide three methods:


You have still second selection - consider to use DefaultTableModel.
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Walter,

You can also use the TableModel interface. Can have more customization.

Regards,
Clivant
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!