我无法找到一种方法以编程方式获取单元格的大小,从而在javafx.scene.control.TableView中显示行和列索引。
如何按行和列索引查找TableCell或TableColumn?
我搜索了很多,但没有找到。
由于 保罗
答案 0 :(得分:0)
我没有找到明确的方法,但出于测试目的,接下来应该可以工作:
导线方法:
// run it next way: traverse(table, -1, -1);
public void traverse(Node node, int row, int column) {
//System.out.println(node.getClass()); // uncomment to see how traverse works
// once we found a TableRow all children are from that row, so we save it's number
int newRow = (node instanceof TableRow) ? ((TableRow) node).getIndex() : row;
// same for the column, although there would be only one child
int newColumn = (node instanceof TableCell) ? ((TableCell)node).getIndex() : column;
// in my demo table cells are text, change to your implementation class for custom cells
if (node.getClass().getName().contains("LabeledText")) {
String text = ((com.sun.javafx.scene.control.skin.LabeledText) node).getText();
if (!text.isEmpty()) { // this check is just to filter empty rows
System.out.println("### " + text);
System.out.println("# Row: " + row + " Column: " + column);
System.out.println("# Height: " + node.getBoundsInParent().getHeight());
}
}
// traverse code
if (node instanceof Parent) {
Parent parent = (Parent) node;
parent.getChildrenUnmodifiable().forEach(n -> traverse(n, newRow, newColumn));
}
}