JavaFX - 当鼠标单击tabpane时如何收听tab down按钮?

时间:2014-07-03 09:24:30

标签: javafx-2 actionlistener tabpanel

Tab Down Button on TabPane

如何在TabPane中的Tab Down按钮上有一个onMouseClicked监听器?

1 个答案:

答案 0 :(得分:3)

我们可以向TabPane添加一个MouseEvent处理程序,如果在那里点击则找到箭头:

tabPane.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent> () {
    @Override
    public void handle(MouseEvent mouseEvent) {
        EventTarget eventTarget = mouseEvent.getTarget();
        if (eventTarget instanceof StackPane) {
            StackPane stackPane = (StackPane) eventTarget;
            ObservableList<String> styleClasses = stackPane.getStyleClass();
            for (String styleClass : styleClasses) {
                if ("arrow".equals(styleClass) == true) {
                    //TODO
                    System.out.println("arrowEvent");
                }
            }
        }
    }
});