aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes dumb question about jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "dumb question about jtable" Watch "dumb question about jtable" New topic
Author

dumb question about jtable

morten wilken
Greenhorn

Joined: May 25, 2002
Posts: 13
hi all,
i have made my own tablemodel, but cannot get the jtable to display column names?
i have implemented the getColumnName() method in the tablemodel, and i kinda hoped this was enough.
i have also tried to do: jtable.setAutoCreateColumnsFromModel(true);
in the hope that that would help
but how do i do this?
sincerely
morten wilken
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
I had no problem getting the column name to display by overriding getColumnName. Maybe the problem is in the code in the overridden method.
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
I had no problem getting the column name to display by overriding getColumnName. Maybe the problem is in the code in the overridden method.
morten wilken
Greenhorn

Joined: May 25, 2002
Posts: 13
hi robin,
my code is this:
public String getColumnName(int index) {
System.out.println(fieldInfo[index].getName().trim());
return (fieldInfo[index].getName().trim());
}
i can see that the corrct names gets written to the console, so i know it gets called.
i instantiate the jtable thusly:
TableModel tm = new TableModel(di, fi);
JTable jt = new JTable(tm);
jt.setAutoCreateColumnsFromModel(true);
tablePanel.add(jt);
can you spot any problems here?
sincerely
morten wilken
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
Not sure what's wrong. Here's the table model I used:
TableModel dataModel = new AbstractTableModel() {
public String getColumnName(int column) {return cachedFieldInfo[column].getName();}
... other methods overridden ...
};
Also I had setAutoCreateColumnsFromModel(false). You could try this.
I need to leave for a while. Good luck!
morten wilken
Greenhorn

Joined: May 25, 2002
Posts: 13
hi all,
i found my problem and just thought i would post it here if anyone else has the same trouble.
i had to put the jtable in a jscrollpane for the header of the tble to show.. not sure why, but now it works
sincerely
morten wilken
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dumb question about jtable