table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if(e.getClickCount() == 2) { int index = table.getSelectedRow(); } } });
filesTable.addMouseListener( new TableMouseAdapter()); public class TableMouseAdapter extends MouseAdapter { public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) { table.getSelectedRow() } } }
swing中鼠标右键对JTable的选择不起作用,所以应该改成这样table.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int index = ((JTable)e.getSource()).rowAtPoint(e.getPoint()); if( index >= 0 && ((JTable)e.getSource()).isRowSelected(index) ) { /*** INSERT YOUR CODE ***/ }
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2) {
int index = table.getSelectedRow();
}
}
});
public class TableMouseAdapter extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() >= 2) {
table.getSelectedRow()
}
}
}
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = ((JTable)e.getSource()).rowAtPoint(e.getPoint());
if( index >= 0 && ((JTable)e.getSource()).isRowSelected(index) ) {
/*** INSERT YOUR CODE ***/
}
}
}
});