How to hide the horizontal Scrollbar of a ListView

2019-01-26 08:16发布

问题:

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.

回答1:

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;
}


回答2:

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.



回答3:

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.