如何在JavaFX中从TableView获取TableHeaderRow? [英] How to get TableHeaderRow from TableView nowadays in JavaFX?

查看:845
本文介绍了如何在JavaFX中从TableView获取TableHeaderRow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了如何使用代码在许多地方获取表头的示例

I saw examples on how to get table header in many places with code

TableHeaderRow header = (TableHeaderRow) tableView.lookup("TableHeaderRow");

就像这里:如何防止TableView在javaFX 8中执行TableColumn重新排序?

但是这段代码为我返回 null

But this code returns null for me.

如何到达 TableHeaderRow 然后?

推荐答案

TableHeaderRow Skin 创建,默认 Skin 在创建css之前不会创建。

The TableHeaderRow is created by the Skin and the default Skin is not created until css is applied.

你可以打电话给 TableView 添加到场景后 applyCss code>并在此次调用后访问 TableHeaderRow

You could call applyCss after adding the TableView to a Scene and access the TableHeaderRow after this call.

或者监听<$ c中的更改$ c>皮肤并在设置皮肤后执行该代码。

Alternatively listen for changes in the Skin and execute that code after the skin has been set.

Fu此外,我建议使用 TableViewSkinBase.getTableHeaderRow 来检索标题行,而不是使用 lookup (您正在使用<无论如何,code> com.sun 包。)

Furthermore I'd recommend using TableViewSkinBase.getTableHeaderRow to retrieve the header row instead of using lookup (you're using com.sun packages anyway).

tableView.skinProperty().addListener((a, b, newSkin) -> {
    TableHeaderRow headerRow = ((TableViewSkinBase) newSkin).getTableHeaderRow();
    ...
});

这篇关于如何在JavaFX中从TableView获取TableHeaderRow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆