Reputation: 1948
After setting a JTable column to invisible, i cannot get reference to the component.
Component cellEditor;
String name;
String value;
// loop row then column
for(int j=0 ; j<tolCol ; j++){
/* get cell name in JTable */
System.out.println(j + " " + ((JTable)comp).getModel().getValueAt(0, j));
tce = ((JTable)comp).getCellEditor(0, j); // <-- ArrayIndexOutOfBounds
}
When i use System.out.println(j + " " + ((JTable)comp).getModel().getValueAt(0, j)); i manage to print all the value out. Is there anything else i need to do to get the reference of component?
Upvotes: 2
Views: 1427
Reputation: 324157
Why do you think you need the cell editor of a hidden column. It sounds like a bad design.
Even your code to access the data is not corrent because the model and the view can be different. The order of the columns in the model never change. Lets assume your table model can contain the following data in 3 columns: "String", "Integer", "Date". Now lets assume the user reorders the table by dragging the "Date" columns to the first column of the table.
Now when you access table.getModel().getValueAt(row, 0) you will get a "String" value.
When you access table.getCellEditor(row, 0) you will get the editor for a "Date" object.
To access the default editor for a given Class type you can do:
Class clazz = table.getModel().getColumnClass(0);
TableCellEditor tce = table.getDefaultEditor( clazz );
Upvotes: 1
Reputation: 63708
After setting a JTable column to invisible
If you have removed the column in order to make it invisible, then you will get the ArrayIndexOutOfBoundException
. But you can access ((JTable)comp).getModel().getValueAt(0, j)
Upvotes: 1