I am currently having an issue with setting values to Checkbox in JTable. I need to store Boolean values per checkbox in rows of the table. I can display default(false) checkbox, but once I click check box, I get an exception; java.lang.ArrayIndexOutOfBoundsException: 0. I am not too familiar with multi arrays with Boolean and I cannot seem to figure out which part of my code is incorrect.
public static final int CHECKBOX= 0;
private final List<Data> datas;
private static boolean CHECKBOX_RENDERED[][] = new boolean[][]{};
private static Arrays array = null;
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (rowIndex >= this.datas.size()) {
return null;
}
Data theData= this.datas.get(rowIndex);
if (theData== null) {
return null;
}
//Initialize the boolean field with table dimension
CHECKBOX_RENDERED = new boolean[datas.size()][columnIndex];
switch(columnIndex) {
case CHECKBOX:
array.fill(CHECKBOX_RENDERED[rowIndex], false);
return false; //default
default:
throw new IllegalArgumentException("Invalid column index");
}
}
@Override
public void setValueAt(Object value, int row, int column) {
if (column == CHECKBOX) {
Data data= this.datas.get(row);
if (data!= null && value instanceof Boolean) {
if (CHECKBOX_RENDERED[row][column]) {
CHECKBOX_RENDERED[row][column] = false;
//I think I need to set Boolean value to the specific array field
//but how.?
} else {
CHECKBOX_RENDERED[row][column] = true;
}
fireTableCellUpdated(row, column);
}
}
}
Aucun commentaire:
Enregistrer un commentaire