开发者

Cannot access the Jtable column data after set invisible

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?


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)


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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜