栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JavaFX-将TableView的高度调整为行数

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JavaFX-将TableView的高度调整为行数

如果您希望此操作有效,则必须设置

fixedCellSize

然后,您可以将的高度

TableView
与表格中包含的项目大小乘以固定单元格大小绑定在一起。

演示:

@Overridepublic void start(Stage primaryStage) {    TableView<String> tableView = new TableView<>();    TableColumn<String, String> col1 = new TableColumn<>();    col1.setCellValueFactory(cb -> new SimpleStringProperty(cb.getValue()));    tableView.getColumns().add(col1);    IntStream.range(0, 20).mapToObj(Integer::toString).forEach(tableView.getItems()::add);    tableView.setFixedCellSize(25);    tableView.prefHeightProperty().bind(tableView.fixedCellSizeProperty().multiply(Bindings.size(tableView.getItems()).add(1.01)));    tableView.minHeightProperty().bind(tableView.prefHeightProperty());    tableView.maxHeightProperty().bind(tableView.prefHeightProperty());    BorderPane root = new BorderPane(tableView);    root.setPadding(new Insets(10));    Scene scene = new Scene(root, 400, 400);    primaryStage.setScene(scene);    primaryStage.show();}

注意:我乘以fixedCellSize *(数据大小+ 1.01)以包含标题行。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/496242.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号