This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes what has to be added for a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "what has to be added for a JTable" Watch "what has to be added for a JTable" New topic
Author

what has to be added for a JTable

Allen Chan
Ranch Hand

Joined: Jun 07, 2002
Posts: 64
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

Joined: May 15, 2002
Posts: 116
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.


Even crazy and silly looking problems are sometimes real.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what has to be added for a JTable
 
Similar Threads
JTable refreshing problem
My JTable is a bit confused
JTable type yes/no
JTable
JTable & JDBC