?
Solved

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

Posted on 2014-04-02
5
Medium Priority
?
399 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:Ahmet Ekrem SABAN
  • 3
  • 2
5 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 2000 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:Ahmet Ekrem SABAN
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 2000 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:Ahmet Ekrem SABAN
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

809 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