In the previous section, you have learnt about the creation of JTable without column headers. In this example you will learn how to set the column headers in JTable using JTableHeader. Java provides some method and APIs that helps you in setting the column headers in JTable. For more, go to the example.
Description of program:
This program will help you in setting the column headers in JTable. First of all, program creates a table that has some data in row and column format by using the JTable constructor. This table hasn't any column headers initially. For setting the column headers use the JTableHeader that helps you for constructing the JTableHeader that depends on its initialized column model in the TableColumnModel object. The header object adds in JScrollPane and JScrollPane adds in the Panel that will add in the frame which appears you on the screen. Exercise this and check it out.
Description of code:
This is the constructor of JTableHeader class that is used for constructing the JTableHeader with initialized value in the JTableColumnModel. The object of JTableHeader is to manage the header of JTable.
This method takes table header from the JTable.
Here is the code of program:
Output of program:
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: April 14, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles