How to change JTable column names "on the fly"?

Hello!

For a Java project, I need to rename the JTable columns on the fly. I wrote a small test code, where the change of the column names becomes visible only when one clicks on the column name.

Can you tell what to do so that the column name changes whenever the first row content is changed?

Thank you for your support!
ASimpleMouseListener.java
RenameTableColumnNames.java
LVL 1
Ahmet Ekrem SABANSenior IT consultantAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
After the loop, try calling

table.getTableHeader().repaint();

Open in new window

0
 
CEHJConnect With a Mentor Commented:
Can you tell what to do so that the column name changes whenever the first row content is changed?
You need a TableModelListener to do that
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
I am using a TableModelListener now, but still have problems, as you can see when executing the attached code. Again, the column name change is visualized when clicking on any column name, but not before.
RenameTableColumnNames.java
0
 
CEHJCommented:
:)
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Here is the example that fits better to the project framework I am working with. I post it just to have the complete answer for me.
PanelView.java
RenamePanelTableColumnNames.java
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.