如果我在Jtable行或列上单击鼠标左键,则控制台上的输出应该是“单击鼠标左键”,对于右键也应该输出“右键单击”
答案 0 :(得分:1)
不要问这些“重复”的问题,不要问你的好朋友谷歌吗?或者只是查看API文档?
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");
}
}
});