0

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?

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
merlachandra
  • 306
  • 2
  • 16

3 Answers3

2

you have to read how

works,

you have to understand both concepts, simple example here, another here

Community
  • 1
  • 1
mKorbel
  • 109,107
  • 18
  • 130
  • 305
1

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
}
JB Nizet
  • 657,433
  • 87
  • 1,179
  • 1,226
1

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)

Guillaume Polet
  • 46,469
  • 4
  • 81
  • 115