• Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamic jtable

 
Prahlad Joshi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to create a table whose column and row names will be entered at run time by the user(and hence the size will depend on the number of strings entered by him).
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The DefaultTableModel provides all the functionality you require.
 
Ganesh Chinni
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in case if you wanted a sample code to dynamically add rows to table,

DefaultTableModel model;
JTable table;

model = new DefaultTableModel();

model.addColumn("Name");
model.addColumn("Phone");

table=new JTable(model);

for(i=0;i<=5;i++) {
Object[] rowData = {"XYZ","1236"};
model.insertRow(i,rowData);
}


Regards,
Ganesh
SCJP
SCWCD
SCBCD
[ October 24, 2007: Message edited by: Ganesh Chinni ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!