Always show vertical scrollbar for JavaFX ListView

后端 未结 1 364
清酒与你
清酒与你 2021-01-23 01:49

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

相关标签:
1条回答
  • 2021-01-23 02:31

    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();
      }
    
    0 讨论(0)
提交回复
热议问题