Search code examples
javaswingjtabletablemodel

Display Table Titles with a Table Model in Java Swing


I would like to create a table with the constructor method JTable(TableModel). What exact methods in the TableModel do I need to display the titles of each column?


Solution

  • You need to embed your JTable within a JScrollPane and the column headings will be shown automatically:

    JScrollPane sp = new JScrollPane(new JTable());