5

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);
    }
}
Joe Ernst
  • 508
  • 6
  • 18
  • You shouldn't need to request the layout when the divider moves: that should happen automatically (because the size of the panes change). Why do you need this? – James_D Jul 28 '15 at 19:53
  • I'm trying to troubleshoot a bug in my application that has something to do with resizing the panes within the SplitPane. However, in order to troubleshoot it I need to know how to "listen" for the divider position being changed. Once I get that figured out I can continue troubleshooting my **actual** problem. – Joe Ernst Jul 28 '15 at 21:21
  • Why not to use more specific layout other than Pane? – Uluk Biy Jul 29 '15 at 04:16

1 Answers1

5

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

Andrew
  • 4,574
  • 26
  • 31