问题
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.
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.
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.
回答1:
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);
}
So as of now use lookup() for the rendered tablerows.
Set<Node> tableRows = tableView.lookupAll("TableRow");
来源:https://stackoverflow.com/questions/52630608/accessing-a-tablerows-style-data-in-a-tableview