Hi,welcome to our Java JTable Add Column Headers tutorial.

The Plan

  • Simple JTable With several columns and Rows.
  • We render a column header on top of all our columns.
  • I have used Eclipse Lunar IDE.


  • JTable derives from Javax.Swing.JComponent.
  • Implements a couple of interfaces including ListSeelectionListener, CellEditorListener, TableModelListener, Scrollable among others.
  • It’s used to edit and display regular two-dimensional data in cells.
  • It doesn’t cache data, just displays it.
  • It allows a lot of customizations in terms of its rendering.
  • They are typically contained inside a JScrollpane.
  • Can enable filtering and sorting using Rowsorter.
  • DefaultTableModel is a model implementation using, yes, Vector of Vectors of Objects to store the values of cells.

Our Project

 import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

public class ColumnHeader  extends JFrame{

    public ColumnHeader()

        super("JTABLE TUTOR");

      //SET DATA
        Object[][] data=
              {"1","Man Utd","Luis Van gaal","86"},
                  {"2","Chelsea","Jose Mourinho","84"},
                  {"3","Man City","Manuele Pelegrini","82"},
                  {"4","Arsenal","Arsene Wenger","80"},
                  {"5","Liverpool","Brendan Rodgers","78"},

        String[] columnHeaders={"Position","Team","manager","Points"};

        //CREATE TABLE
        JTable table=new JTable(data,columnHeaders);
        table.setPreferredScrollableViewportSize(new Dimension(500,80));

        //CUSTOM WIDTH
        TableColumn col0=table.getColumnModel().getColumn(0);
        TableColumn col1=table.getColumnModel().getColumn(1);
        TableColumn col2=table.getColumnModel().getColumn(2);


        JScrollPane pane=new JScrollPane(table);


    public static void main(String[] args) {
      ColumnHeader c=new ColumnHeader();

Best Regards.

Categorized in: