在TableView中访问TableRow的样式数据 [英] Accessing a TableRow's style data in a TableView

查看:69
本文介绍了在TableView中访问TableRow的样式数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一些TestFX代码,这些代码将遍历TableView组件并检查每行的背景色设置是否正确.

I'm trying to write some TestFX code that will loop through a TableView component and check the background colour for each row is set correctly.

我无法解决的是如何实际构造循环以遍历TableRows而不是实际数据.我尝试使用sourceTable.getItems(),但这仅使我可以访问包含数据的对象.但是我需要比这更低一些,并实际检查CSS标签的背景颜色.

What I can't work out is how to actually construct the loop to go through the TableRows as opposed to the actual data. I've tried using sourceTable.getItems() but that just gives me access to the object containing the data. But I need to go lower down than that and actually examine the background-colour of the CSS tag.

我知道TableRow具有getStyle函数,该函数将返回我要查找的数据,但是我对如何构造将遍历每一行的适当迭代感到困惑.

I know that a TableRow has a getStyle function, which will return the data I'm looking for, but I'm at a loss at how to construct the appropriate iteration that will go through each individual row.

推荐答案

我的第一个想法是使用queryAccessibleAttribute()方法.但是很遗憾,它无法正常工作.可能有人可以纠正我.

My first thought is to use queryAccessibleAttribute() method.. but unfortunately it is not working working as expected. May be someone can correct me.

for (int i=0;i<tableView.getItems().size();i++){
    TableRow row = (TableRow) tableView.queryAccessibleAttribute(AccessibleAttribute.ROW_AT_INDEX,i);
}

所以从现在开始,对呈现的表行使用lookup().

So as of now use lookup() for the rendered tablerows.

Set<Node> tableRows = tableView.lookupAll("TableRow");

这篇关于在TableView中访问TableRow的样式数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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