使用javafx在文本区域和表视图中检测辅助鼠标按钮

时间:2012-10-20 00:29:59

标签: javafx-2

private void gotoRightClick(){

     textArea.setOnMouseClicked(new EventHandler<MouseEvent>(){

        @Override
        public void handle(MouseEvent event) {
            if(event.isSecondaryButtonDown())
            {
                System.out.println("right click pressed in text area");
            }
        }
    });

  tableView.setOnMouseClicked(new EventHandler<MouseEvent>(){

        @Override
        public void handle(MouseEvent e) {
            if(e.isSecondaryButtonDown())
            {
                System.out.println("right click pressed in table view");
            }
        }
    });
}

没有一个事件被发现可以帮助我吗? 谢谢你的进步

1 个答案:

答案 0 :(得分:0)

试试这个:

this.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                if (event.getButton().equals(MouseButton.SECONDARY)) {
                    //do something
                }
            }
        });