Detect left mouse click and right mouse click on JTable (SWING)

6.7k Views Asked by At

If i click left mouse button on Jtable row or column then output on console should be "Left button clicked" in the the same way for Right button also the output should be "Right button clicked"

1

There are 1 best solutions below

2
On BEST ANSWER

Instead of asking these "duplicate" questions, don't you just ask your very good friend, Google? Or just look through the API doc?

table.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent arg0) {
                if (arg0.getButton() == MouseEvent.BUTTON1){
                    System.out.println("Left button clicked");
                } else if (arg0.getButton() == MouseEvent.BUTTON2){
                    System.out.println("Middle button clicked");
                } else if (arg0.getButton() == MouseEvent.BUTTON3) {
                    System.out.println("Right button clicked");
                } 
            }
        });