动态更改JTable中的列标题文本 [英] Dynamically changing the column header text in JTable

查看:104
本文介绍了动态更改JTable中的列标题文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含3列的表,其标题中包含以下值:'No.','X [mm]','Y [mm]'。此表包含以毫米为单位的点坐标。我有一个复选框,用于检查表格应该重新填充以显示以英寸为单位的坐标。此外,列标题值应为:'No','X [in]','Y [in]'。

I have a table with 3 columns which have the following values in the headers: 'No.', 'X [mm]', 'Y [mm]'. This table contain the coordinates of points in millimeters. I have a checkbox on checking of which the table should repopulate to show the coordinates in inches. Moreover, the column header values should be: 'No.', 'X [in]', 'Y [in]'.

简而言之,我想动态更改表格的标题文本。

In short I want to dynamically change the header text of the table.

详细信息:
该表是JTable的子类。此外,已将'DefaultTableModel'的子类设置为表的模型。我在datamodel子类的构造函数中提供了头值。

In detail: The table is a subclass of JTable. Moreover, a subclass of 'DefaultTableModel' has been set as the model for the table. I have provided the header values in the constructer of the datamodel subclass.

有什么想法吗?我的应用程序只与jdk v1.4兼容,所以如果解决方案与verion兼容将是好的:)

Any idea? My application is compatible with only jdk v1.4 so it would be good if the solution is compatible with the verion :)

推荐答案

您可以直接更新TableColumnModel:

You can update the TableColumnModel directly:

JTableHeader th = table.getTableHeader();
TableColumnModel tcm = th.getColumnModel();
TableColumn tc = tcm.getColumn(0);
tc.setHeaderValue( "???" );
th.repaint();

这篇关于动态更改JTable中的列标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆