Always show vertical scrollbar for JavaFX ListView

javafx-2

Solution

you could put it into a properly sized ScrollPane and set the vbar policy of the ScrollPane to ALWAYS:

  @Override
  public void start(Stage primaryStage) throws Exception {
    ScrollPane pane = new ScrollPane();
    ListView<String> list = new ListView<String>();
    ObservableList<String> items = FXCollections.observableArrayList(
            "Single", "Double", "Suite", "Family App");
    list.setItems(items);
    pane.prefWidthProperty().bind(list.widthProperty());
    pane.prefHeightProperty().bind(list.heightProperty());
    pane.setContent(list);
    pane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
    Group group = new Group();
    group.getChildren().add(pane);
    Scene scene = new Scene(group, 500, 500);
    primaryStage.setScene(scene);
    primaryStage.show();
  }

Problem

ListView appears to already have a scrollbar. I want the scrollbar to always be visible. The reason is because I'm putting a header on it and a button in the corner between the scrollbar and header. How can I get the ListView scrollbar to always display?

Original source