Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTableHeader not showing

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first experience using a JTable, and I'm using a DefaultTableModel. What do I need to do to get the header to show?

In the test code below, I've gotten to the point of setting the header value (I think), but I'm stuck after that. I'm sure this is something simple, but I'm missing it.

 
Paul Clapham
Sheriff
Posts: 21312
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm not mistaken, you only get the column headings if your JTable is in a JScrollPane. Yours isn't, it's in a JPanel that's in the JScrollPane. The intermediate panel looks unnecessary to me.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure enough, that seems to be it! Thanks for the help.

I broke this out of a much larger piece of code to isolate the problem, and there are a still some unnecessary pieces here. I see I was headed down the wrong path with the code I had in bold.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic