I have a custom TableCellRenderer
(ValueRenderer) for a JTable, the cell is a Checkbox
.
I have attached an ItemListener
to the valueRenderer to listen to the checkbox's state change (selected/deselected) as mentioned by this example.
My problem is that inside the itemStateChanged(ItemEvent e)
, I do not know how to get the row in which this checkbox is contained knowing that the ItemEvent
source is the ValueRenderer.
Can you help me?
Here is some of my code:
Custom TableCellRender:
public class ValueRenderer extends JCheckBox implements TableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
this.setSelected((Boolean) value);
return this;
}
}
ItemListener:
public class TableRowCheckBoxListener implements ItemListener {
private JTable hqlRequestTable;
public TableRowCheckBoxListener(JTable hqlRequestTable) {
this.hqlRequestTable = hqlRequestTable;
}
@Override
public void itemStateChanged(ItemEvent e) {
/*How do I get the row which contains the checkbox clicked knowing that :
e.getSource() == ValueRenderer
e.getItem() == ValueRender
*/
}
}