Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 254
mirzak Avatar asked Nov 05 '14 17:11

mirzak


1 Answers

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:

@Override
public void start(Stage primaryStage) {
    final SplitPane splitPane = new SplitPane();
    splitPane.setOrientation(Orientation.HORIZONTAL);
    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);

    primaryStage.setScene(scene);
    primaryStage.show();

    splitPane.lookupAll(".split-pane-divider").stream()
            .forEach(div ->  div.setMouseTransparent(true) );

}
like image 151
José Pereda Avatar answered Nov 02 '22 05:11

José Pereda