Bick
Bick

Reputation: 18521

Is there a way to add a row selected listener on JTable?

I am using addMouseListener (that has many method to implement)
and can add add keyListener also.
Is there a better way to get a row selected listener?
Thanks.

Upvotes: 3

Views: 21985

Answers (2)

tres2k
tres2k

Reputation: 146

have you tried?

    jTable1.getModel().addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            if(e.getType() == e.UPDATE){
                System.out.println(e.getColumn());
                System.out.println(e.getFirstRow());
                System.out.println(e.getLastRow());
            }
        }
    });

@assylias yeah there is a selected in the question not a changed. My mistake misread the question.

Upvotes: 9

assylias
assylias

Reputation: 328608

If you want to listen to row selection changes (i.e. not value changes inside the row), you can use this: yourJTable.getSelectionModel().addListSelectionListener(yourListener); ?

Upvotes: 33

Related Questions