如何将侦听器添加到SplitPane Divider位置?

时间:2015-07-28 18:03:24

标签: listener javafx-8 splitpane

我无法弄清楚如何倾听" Divider Repositioned" JavaFX 8 SplitPane上的事件。这是一个简单的工作应用程序,只需要添加事件监听器。有人可以帮助我指出正确的方向吗?

public class TestCase extends Application {
    public void start(Stage primaryStage) throws Exception {
        Pane leftPane = new Pane();
        Pane rightPane = new Pane();
        SplitPane splitPane = new SplitPane(leftPane, rightPane);

        // Need to create a listener that fires whenever the SplitPane's Divider is repositioned
        // Within this listener I need access to the leftPane and rightPane so I can call requestLayout()

        primaryStage.setScene(new Scene(splitPane));
        primaryStage.setWidth(800);
        primaryStage.setHeight(600);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

1 个答案:

答案 0 :(得分:3)

您可以使用splitPane.getDividers()获取分隔线,并将ChangeListeners添加到dividers.positionProperty()