giozh
giozh

Reputation: 10068

JTable clicked row listener

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

Answers (2)

Juned Ahsan
Juned Ahsan

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

AllTooSir
AllTooSir

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

Related Questions