始终显示JavaFX ListView的垂直滚动条 [英] Always show vertical scrollbar for JavaFX ListView
本文介绍了始终显示JavaFX ListView的垂直滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ListView似乎已经具有滚动条.我希望滚动条始终可见.原因是因为我要在其上放置标题,并在滚动条和标题之间的角上放置一个按钮.如何使ListView滚动条始终显示?
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?
推荐答案
您可以将其放入适当大小的ScrollPane中,并将ScrollPane的vbar策略设置为始终:
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();
}
这篇关于始终显示JavaFX ListView的垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文