JTable table = new JTable(data, columnNames); JTableHeader header = table.getTableHeader();
JScrollPane scrollPane = new JScrollPane(table); JTableHeader header = scrollPane.getColumnHeader();This example creates a JScrollPane containing a JTable and gets the header of the JTable using the getColumnHeader() method of the JScrollPane. Library: The javax.swing package.