Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying the Column Name for JTabel  RSS feed

 
Mohamed Sanaulla
Bartender
Posts: 3179
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to get the Column names on the JTable. I am creating a JTable at runtime. The sample snippet is given below.

import javax.swing.*;



I am not able to get the Column Name on the top of each column. I am just getting the data values entered to the Table.



Also Added the screen shot of t he output
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mohammed sanaullah:
I am not able to get the Column Name on the top of each column. I am just getting the data values entered to the Table.


Change add(table) to add(new JScrollPane(table)).
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is, a table is actually two components: the JTable itself and its JTableHeader. When used in a JScrollPane the JTableHeader is added automatically, otherwise you have to do it yourself:
 
Mohamed Sanaulla
Bartender
Posts: 3179
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!! Both of them worked.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!