Hello all,
I am writing a java application where I have a Jtable with checkboxes next to the data. If the user checks a box, I want to store a specific value from the data table. I can do this inelegantly by setting setCellSelectionEnabled(true) and adding the following to the event listener:
private class selectionListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent event) {
if (event.getValueIsAdjusting()) {
return;
}
// This will return any value where the user clicks on a cell:
Object value = table.getValueAt(table.getSelectedRow(), (table.getSelectedColumn() - 1));
//debug message for verification:
System.out.println("Selected: " + value.toString());
//Trying to determine who fired the event:
Object source = event.getSource();
System.out.println("From: " + source.toString());
// An array list to store selected values:
selection_array.add(value);
}
Here is some sample output:
Selected: DONE C
From: javax.swing.DefaultListSelectionModel 27296482 ={7}
Is there a method I can invoke that will tell me who the caller was? The checkboxes are embedded in the table via an override to the Default Table model, they weren't explicitly defined by me. So, I think that the listener just knows that it is a cell selection event and is not concerned about the type.