• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what has to be added for a JTable

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic