Reputation: 386
I've two tables in panels. When I click on first table on some cell, its row is getting selected. And when I click on the second table on some cell, its row is also getting selected.
Now, How will I come to know, which table is last clicked. I tried with isRowSelected
on both the tables, both are returning, so I'm not able to find the last clicked table?
Can somebody help me?
Upvotes: 0
Views: 103
Reputation: 47608
Another way to do it is to check the source of the event:
new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getSource()==table1.getSelectionModel()) {
// Event comes from table1
} else if (e.getSource()==table2.getSelectionModel()) {
// Event comes from table2
}
}
}
Of course this is true if and only if the selection model is used by a single table (which is the case if you have not set your own ListSelectionModel)
Upvotes: 1
Reputation: 691775
I don't know if this must be determined from a MouseListener or from a ListSelectionListener, but the simplest solution is similar: use a different listener for each table:
table1.addXxxListener(new XxxListener() {
// here, you know it's table 1
}
table2.addXxxListener(new XxxListener() {
// here, you know it's table 2
}
Upvotes: 1