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
  • 168,117
  • 40
  • 217
  • 433
merlachandra
  • 376
  • 2
  • 17

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,525
  • 20
  • 134
  • 319
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
  • 678,734
  • 91
  • 1,224
  • 1,255
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
  • 47,259
  • 4
  • 83
  • 117