我有以下问题:我想禁用我的TableView的水平滚动条。它可能不可见,但也可能无法水平滚动TableView。水平滚动条的可见性可以在CSS中设置:JavaFX:禁用TableView的水平滚动条
.table-view *.scroll-bar:horizontal *.increment-button,
.table-view *.scroll-bar:horizontal *.decrement-button {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
}
.table-view *.scroll-bar:horizontal *.increment-arrow,
.table-view *.scroll-bar:horizontal *.decrement-arrow {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
-fx-shape: null;
}
来源:How to hide the horizontal Scrollbar of a ListView in JavaFX和https://community.oracle.com/thread/2377826?tstart=0。
这工作正常,但我仍然可以水平滚动TableView(虽然滚动条不可见)。我已将列宽设置如下:
col1.setPrefWidth(table.getPrefWidth()*0.40);
col2.setPrefWidth(table.getPrefWidth()*0.20);
col3.setPrefWidth(table.getPrefWidth()*0.20);
这适用于TableView不显示任何行时。但是,当我填充它(通过按下按钮),列稍微拉伸,这使得TableView水平滚动。
是只能隐藏滚动条,或者你也可以禁用滚动本身?
任何帮助,非常感谢!
尝试给列更窄的宽度摆脱舒展。否则提供一个MVCE。 – 2014-11-06 17:30:05