Java獲取鼠標滾輪按下事件,滾輪按下的事件和鼠標點擊事件都在MouseListener裡面
判定滾輪按下,原始的方法如下:
- public void mouseClicked(MouseEvent e) {
- int modifiers = e.getModifiers();
- if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK){
- System.out.println("middle button click");
- }
- }
當然可以利用SwingUtilities
- public void mouseClicked(MouseEvent e) {
- if (SwingUtilities.isMiddleMouseButton(e)){
- System.out.println("middle button click");
- }
- }