【发布时间】:2018-09-12 11:40:28
【问题描述】:
我正在使用带有 UNCONSTRAINED_RESIZE_POLICY 的 tableView。 我想将所有空列单元格设置为白色背景。
这是当前视图。
我正在尝试搜索空节点,但是即使通过以下代码(测试函数)搜索tableView中包含的所有节点也找不到它:
private void test() {
ArrayList<Node> nodes = getAllNodes(tableView);
nodes.forEach(node -> {
if(node instanceof TableCell) {
if(((TableCell) node).getText() == null || ((TableCell) node).getText().isEmpty()) {
System.out.println(true);
}
}
});
}
public static ArrayList<Node> getAllNodes(Parent root) {
ArrayList<Node> nodes = new ArrayList<Node>();
addAllDescendents(root, nodes);
return nodes;
}
private static void addAllDescendents(Parent parent, ArrayList<Node> nodes) {
for (Node node : parent.getChildrenUnmodifiable()) {
nodes.add(node);
if (node instanceof Parent)
addAllDescendents((Parent)node, nodes);
}
}
【问题讨论】:
-
不太清楚你的意思:列右边的空白不是tableCell,而是tableRowCell(不,你从来没有尝试过抓住单元格;) -由它的 :odd 样式属性处理(它通过 tableCells 发光,因为它们是透明的)。您可以尝试让 tableCell 进行奇怪的样式并将其从 tableRow 中删除
-
@kleopatra 感谢您的回复。我不明白你的意思是让 tableCell 做奇怪的样式并将其从 tableRow 中删除。我既不能通过 css 选择器选择那些空单元格,也不能在我的应用程序中获取对象。那么如何将 tableCell 更改为奇数样式?
-
看看 tableRowCell 是如何做到的,如果不为空,则应用到自定义 tableCell (并仔细阅读我上一条评论中的第一句话:)
标签: css javafx tableview javafx-8