March 4th, 2000, 01:23 PM
Hi,
I have a JTable that shows 5 columns on start. The 5 columns are taken from a TableModle of 6 columns, and are filtered by a TableColumnModle's addColumn method. What I want now is that I want to make the 6th column of the TableModle either show or hide according to some user event. In another word, when the user clicks on the "Show" button, I want the 6th column of the TableModle, which was not showing origionally, to show on the JTalble. When the "Hide" is clicked, remove the 6th column from the table. While it sounds straitforward, I still don't know how to add the column to the table. I know there is a addColumn() method of the TableColumnModle object that adds a TableColumn object to the TableColumnModel and that will notify the JTable to update and show the new column, but the problem is you have to provide the TableColumn object that you want to add, as a parameter, to the addColumn() method. My problem is that I don't know how to get the TableColumn object from the 6th column of my TableModle object. There is no such method as "getColumn(int index)" of TableModle that returns the TableColumn object I wanted.
Could anybody please help me to solve this?
Your help is highly appreciated.
Lifeng
I have a JTable that shows 5 columns on start. The 5 columns are taken from a TableModle of 6 columns, and are filtered by a TableColumnModle's addColumn method. What I want now is that I want to make the 6th column of the TableModle either show or hide according to some user event. In another word, when the user clicks on the "Show" button, I want the 6th column of the TableModle, which was not showing origionally, to show on the JTalble. When the "Hide" is clicked, remove the 6th column from the table. While it sounds straitforward, I still don't know how to add the column to the table. I know there is a addColumn() method of the TableColumnModle object that adds a TableColumn object to the TableColumnModel and that will notify the JTable to update and show the new column, but the problem is you have to provide the TableColumn object that you want to add, as a parameter, to the addColumn() method. My problem is that I don't know how to get the TableColumn object from the 6th column of my TableModle object. There is no such method as "getColumn(int index)" of TableModle that returns the TableColumn object I wanted.
Could anybody please help me to solve this?
Your help is highly appreciated.
Lifeng