• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to populate, clear and append records into JTable

 
Deepa Raghuraman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
I have a table (JTable) with 3 buttons.
when clicked on button "populate", the table must get populate with records,
when clicked on button "clear", the table must get cleared (no records shuld be displayed)
when clicked on button "add", a new record must be added at the end of the table.
how to do this? I needed it very urgently...
Regards,
Deepa Raghuraman
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this -
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
And see if it is of some help.
HTH,
- Manish
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create your JTable with a DefaultableModel.
DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable(model);
To clear :
model.setRowCount(0);
To insert a row,
model.insertRow()
To delete a row :
model.removeRow()
check the javadocs for details.
D>
 
indian greenhorn
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Deepa Raghuraman:
hi friends,
I have a table (JTable) with 3 buttons.
when clicked on button "populate", the table must get populate with records,
when clicked on button "clear", the table must get cleared (no records shuld be displayed)
when clicked on button "add", a new record must be added at the end of the table.
how to do this? I needed it very urgently...
Regards,
Deepa Raghuraman


Hi,
I have given a reply to your query in java.sun.com forum. Now I understand u want the table to be empty with no rows and column at all. Is that right? In that case apart from what I have said do check the reply given by one of the persons here, just before me.
Hope it works for u.
Krishna
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!