Reputation: 30097
How to listen for mouse clicks on table header of JTable
?
If I do like this
getTableHeader().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
//fireOpenActionPerformed();
openActionCascade.actionPerformed(null);
}
}
});
the I can't know which column was clicked when in handler.
Upvotes: 1
Views: 671
Reputation: 208984
"the I can't know which column was clicked when in handler."
What about JTableHeader#columnAtPoint(Point point)
? (i.e. MouseEvent.getPoint)
Returns the index of the column that point lies in, or -1 if it lies out of bounds
Upvotes: 2