I am having an issue at present whereby i need to ba able to hide from the user the data in a particular column in the Jtable as the data is not for user viewing purposes.
I have a seperate class for the TableModel which represent the data which is stored in the JTable so
TableModelClass temp = new TableModelClass; JTableClass main = new JTable(temp);
However i only want to display 9 of the 10 columns in the JTable. Does anyone know the code which will allow me to do this. By the way i need to just hide this column data from the user but it needs to be in the JTable as the column data contains primary keys which are used for data retrieval in other parts of the application.
Is there any code to size the reduce a particular column width size to zero?
In JTable you should find a method that returns the table's TableColumnModel. Notice that TableColumnModel has a removeColumn() method.
That's probably the easiest way to do it for now. But another possibility would be for your table model to be structured so it's one object per row, and that object provides 9 methods to return the 9 visible columns. You could store the primary key data in that object without having to allocate an invisible column to it.
David Winters Junior
posted 10 years ago
Thanks Paul for the reply.
I have decided to use the TableColumn api which has a setMaxwidth() method which will allow me to set the column width to zero.
The issue here is that when the user selects a particular row in the table and clicks on the remove button i need to be able to access the primary key field related to that row so that i can use this value to remove the row in the underlying database.
Originally posted by Brian Cole: This is the second person I've seen who is reluctant to use removeColumn() for some reason, even though it does exactly what they want. This must means Sun named it poorly?
The API documentation doesn't help, either. All it says is "Deletes the TableColumn column from the tableColumns array." I don't know what array that is either, but I'm pretty comfortable with the MVC pattern and it's intuitively clear to me that it's talking about the view. But I certainly wouldn't claim that was obvious.
Nothing else in the API documentation for TableColumnModel says that it is part of the view, and in fact (now I see what you mean) its name suggests it's part of the model.