Reputation: 10068
I have a dynamic JTable
that contains a string matrix, and I need to write a listener that when double click on a row, read a specific column and make some computation on it. Which kind of listener should I use?
Upvotes: 1
Views: 10417
Reputation: 68715
Implement the MouseListener
or extend the MouseAdapter
. You can try something like this:
yourJTable.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent evnt) {
if (evnt.getClickCount() == 1) {
getPropertyFromRow((String)(t_property.getValueAt(yourJTable.getSelectedRow(),0)));
}
}
});
Upvotes: 5
Reputation: 49372
Try using the getClickCount() of MouseEvent
method after implementing the MouseListener
or extending the MouseAdapter
. Sample :
yourJTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) { // check if a double click
// your code here
}
}
});
Upvotes: 0