JavaFx : Disable Divider


I have a JavaFX application with a SplitPane. I want to disable the Divider on SplitPane, so it would not be possible to change its position when application is running. How can I do this?

11/5/2014 5:03:13 PM

Accepted Answer

There's no API for that, so once the scene is shown we have to use a lookup function to find the node by its id. In this case, the Divider has this id: split-pane-divider.

Once we find the node, we set it transparent to mouse events:

public void start(Stage primaryStage) {
    final SplitPane splitPane = new SplitPane();
    splitPane.setDividerPositions(new double[]{0.5});
    splitPane.getItems().add(new StackPane(new Label("Left")));
    splitPane.getItems().add(new StackPane(new Label("Right")));

    Scene scene = new Scene(splitPane, 300, 250);


            .forEach(div ->  div.setMouseTransparent(true) );

11/5/2014 5:14:22 PM

None of the above posts worked for me. I have found this solution which worked for me: This code works for the case when your splitPane is divided in the middle and has only one divider, therefore the divider's position is set to 0.5. If you don't know the position of the divider, you can get it by divider.getPosition();.

        Divider divider = splitPane.getDividers().get(0);
    divider.positionProperty().addListener(new ChangeListener<Number>()      
        public void changed( ObservableValue<? extends Number> observable, Number oldvalue, Number newvalue )

This code is in the initialize() method of the GUI Controller class.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow