Is there a way to add a row selected listener on JTable?
21,754
Solution 1
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);
?
Solution 2
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.
Author by
Bick
Updated on February 16, 2020Comments
-
Bick over 4 years
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.-
kleopatra over 12 yearsplease clarify what you really want: be notified when the selection of a row changed or when the data of a row changed? The two answers are for one of those requirements :-) Apart from that, in Swing you never-ever want a keyListener and rarely a mouseListener.
-
-
nIcE cOw over 12 years+1, It did helped me :-), the same goes for the above answer too.
-
nIcE cOw over 12 years+1, It did helped me :-), the same goes for the below answer too.