I have created a Table and for one of the columns with index 2 which is having a JPanel with multiple JCheckBox. I have set cell editor CheckBoxCellEditor to select and edit the checkbox.
When I select one checkbox from panel, the cell editor is calling getTableCellEditorComponent() and returning the component which is fine.
But when I select another column with index 1, instead of calling TableCellListener, getCellEditorValue() of cell editor is getting called and returning the value. Hence I am not able to capture the checkbox in column 1.
Code: Cell editor
class CheckBoxCellEditor extends AbstractCellEditor implements TableCellEditor{
JPanel panel = new JPanel(new FlowLayout());
AI38DataModel dataModel;
@Override
public Object getCellEditorValue() {
return values;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
if(value!=null){
//panel.removeAll();
List<AI38BetModelTable> modelList = dataModel.getModelList();
LinkedHashMap<String, JPanel> elePanelMap = dataModel.getElePanelMap();
if(modelList!=null || !modelList.isEmpty() || !elePanelMap.isEmpty()){
AI38BetModelTable model = modelList.get(row);
String key = dataModel.getPanelEleStringKey(model.getSelectedEvent().getEventCode(), model.getSelectedBetCode(), model.getElement(), (Set<Integer>)value);
panel = elePanelMap.get(key);
}
}
values = (Set<Integer>)value;
return panel;
}
Main class:
CheckBoxCellEditor CBCEditor = new CheckBoxCellEditor();
infoTable.getColumnModel().getColumn(2).setCellEditor(CBCEditor);
Table cell listener :
AbstractAction action = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
TableCellListener tcl = (TableCellListener) e.getSource();
AI38BetModelTable model = modelList.get(tcl.getRow());
Integer betCode = model.getSelectedBetCode();
Integer eventCode = model.getSelectedEvent().getEventCode();
if(tcl.getRow()==1){
boolean isReporting = (boolean) tcl.getNewValue();
}
}
};
TableCellListener tcl = new TableCellListener(infoTable, action);
selected check box in column 3 - this operation is calling getTableCellEditorComponent
then clicked on checkbox in column 2 - This operation instead of calling TableCellListener , calling the getCellEditorValue of cell editor