Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to populate, clear and append records into JTable

 
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
 
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
 
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>
 
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic