How to hide the horizontal Scrollbar of a ListView in JavaFX

前端 未结 3 1359
梦毁少年i
梦毁少年i 2020-12-16 18:39

How can I hide the horizontal scrollbar of a ListView? I tried it in different ways and probably it\'s totally easy, but I just can\'t get it to run.

相关标签:
3条回答
  • 2020-12-16 19:33

    Bit of a hack, but this should do it. In the CSS:

    .list-view .scroll-bar:horizontal {
        -fx-opacity: 0;
        -fx-padding:-7;
    }
    

    Note that the scroll bar is still there, and mouse gestures around where it "should" be will result in scroll behavior.

    0 讨论(0)
  • 2020-12-16 19:41

    Try this in the CSS:

    .list-view .scroll-bar:horizontal .increment-arrow,
    .list-view .scroll-bar:horizontal .decrement-arrow,
    .list-view .scroll-bar:horizontal .increment-button,
    .list-view .scroll-bar:horizontal .decrement-button {
        -fx-padding:0;
    }
    
    0 讨论(0)
  • 2020-12-16 19:43

    I think that would be nicer a ListCell with a Pane(for example StackPane) and a Label inside that will have the ellipsis functionality:

    StackPane pane = new StackPane();
    pane.setStyle("-fx-border-color:red;");
    pane.setMinWidth(0);
    pane.setPrefWidth(1);
    pane.getChildren().add(label);
    

    You can have a look at this link.

    The same solution could be used for other ListCells complex.

    0 讨论(0)
提交回复
热议问题