Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add listeners to SplitPane Divider positions?

I can't figure out how to listen for a "Divider Repositioned" event on a JavaFX 8 SplitPane. Here is a simple working Application that just needs the event listener added. Can someone help point me in the right direction?

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);
    }
}
like image 768
Joe Ernst Avatar asked Jul 28 '15 18:07

Joe Ernst


1 Answers

You can get the dividers with splitPane.getDividers() and add ChangeListeners to the dividers.positionProperty().

like image 187
Andrew Avatar answered Nov 09 '22 03:11

Andrew