Suzan Cioc
Suzan Cioc

Reputation: 30097

How to listen for mouse clicks on table header of JTable?

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

Answers (1)

Paul Samsotha
Paul Samsotha

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

Related Questions