Search code examples
javaswingjtablejtableheader

Change column header in a JTable


This is my table right now :

enter image description here

This is the code that I can change the column title:

table.getColumnModel().getColumn(0).setHeaderValue("Lecturersssss");

But the column title would not change until I hover the mouse on the Lecturer column header.

Even when i use table.repaint() after this code, it won't change. Do you guys have any idea how can I solve this issue ?

Thanks.


Solution

  • JTableHeader header= table.getTableHeader();
    TableColumnModel colMod = header.getColumnModel();
    TableColumn tabCol = colMod.getColumn(0);
    tabCol.setHeaderValue("Lecturersssss");
    header.repaint();