Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTable selection change event handling: find the source table dynamically

I've implemented my own event handler and added it to the selection model of the table:

table.getSelectionModel().addListSelectionListener(event);

And implemented the method for "event" (mentioned above):

public void valueChanged(ListSelectionEvent e) {
    log.debug("value changed");
}

Unfortunately the event fires twice if I chance the selection and it doesn't seem possible to find the associated table, because e.getSource provides javax.swing.DefaultListSelectionModel.

Hence my questions are:

1) Why does it fire twice although the eventListener is only registered once?

2) How can I find the table for which the selection applies? The DefaultListSelectionModel doesn't seem to offer any getSource() or similar.

Many thanks!

like image 690
MrG Avatar asked Nov 30 '22 20:11

MrG


1 Answers

Thanks Draemon..It Works fine....

Our Code

vMachinesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

    public void valueChanged(ListSelectionEvent lse) {
        if (!lse.getValueIsAdjusting()) {
            System.out.println("Selection Changed");
        }
    }
});

Thanks By

TF Team

like image 71
Think Force Avatar answered Dec 10 '22 03:12

Think Force