• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what has to be added for a JTable

 
Allen Chan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to figure out how to display the data I read from db in JTable, here is part of my code
try{
int i=0;
Data app= new Data(dbfile);
for(i=1; i<app.getRecordCount(); i++){
DataInfo d= app.getRecord(i);
FieldInfo[] fd = d.getFields();
String[] values = d.getValues();
if(i==1){
for(int k=0; k<fd.length-1; k++){
//columnHeads.addElement(fd[k].getName());
System.out.println(fd[k].getName());
}
for(int k=0; k<values.length - 1; k++){
//rows.addElement(values[k]);
System.out.println(values[k]);
}
}
}
// display table with ResultSet contents
columnHeads.addElement("field1");
columnHeads.addElement("field2");
columnHeads.addElement("field3");
rows.addElement("value1");
rows.addElement("value2");
rows.addElement("value3");
table = new JTable( rows, columnHeads );
JScrollPane scroller = new JScrollPane( table );
Container c = getContentPane();
c.remove( 1 );
c.add( scroller, BorderLayout.CENTER );
c.validate();

}catch(Exception ex){
System.out.println("IO Exception 123");
}
// it keeps giving errors
what do I need to modify to be able to fix it?
Thanks a lot.
 
parthiban subramaniam
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
try this first
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

and once u understand those
try this
http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
cheers,
parthi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic