Solved

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

Posted on 2014-04-02
5
391 Views
Last Modified: 2014-04-03
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
0
Comment
Question by:sae1962at
  • 3
  • 2
5 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 500 total points
ID: 39973005
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
 
LVL 1

Author Comment

by:sae1962at
ID: 39973101
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39973410
After the loop, try calling

table.getTableHeader().repaint();

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39974315
:)
0
 
LVL 1

Author Comment

by:sae1962at
ID: 39974787
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 99
throw exception 21 66
printf performancy 11 83
how to debug htl and js pages 8 53
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question