Solved

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

Posted on 2014-04-02
5
387 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now