2013-06-19 235 views
0

右擊我想運行通過一個切換按鈕,鼠標右鍵點擊一個階段,上切換按鈕

ToggleButton tb = new ToggleButton(); 

我應該用什麼方法OnMouse?

回答

1

嘗試一下本作onPressed:

tb.setOnMousePressed(new EventHandler<MouseEvent>() { 
    @Override 
    public void handle(MouseEvent mouseEvent) { 
    if (mouseEvent.isSecondaryButtonDown()){ 
     System.out.println("hi"); 
    } 
    } 
}); 

爲onReleased:

tb.setOnMouseReleased(new EventHandler<MouseEvent>() { 
    @Override 
    public void handle(MouseEvent mouseEvent) { 
    if (mouseEvent.getButton().equals(MouseButton.SECONDARY)) { 
     System.out.println("hi"); 
    } 
    } 
}); 
+0

感謝塞巴斯蒂安,做工精細! –