• 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

dumb question about jtable

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Right! We're on it! Let's get to work tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic