[英]JavaFX: Add UI control to TreeTableView
Let's say i have 2 columns in a TreeTableView and now i want to add a string/Label in the first column and a ProgressBar in the other one. 假设我在TreeTableView中有2列,现在我想在第一列中添加一个字符串/标签,在另一列中添加一个ProgressBar。 How would i accomplish something like this? 我将如何完成这样的事情?
Really appreciate any help! 非常感谢任何帮助!
As correctly pointed out by James_D, you can use ProgressBarTreeTableCell
for a column with ProgressBars. 正如James_D正确指出的那样,您可以将ProgressBarTreeTableCell
用于带有ProgressBars的列。 There is internal supports for some other UI controls such as TextField
, CheckBox
etc. 内部支持其他一些UI控件,例如TextField
, CheckBox
等。
For other UI controls you can create a Custom TreeTableCell
as shown: 对于其他UI控件,您可以创建一个Custom TreeTableCell
,如下所示:
private class ProgressCell extends TreeTableCell<Employee, String> {
final ProgressBar progress = new ProgressBar();
ProgressCell() {
}
@Override
protected void updateItem(String t, boolean empty) {
super.updateItem(t, empty);
if (!empty) {
setGraphic(progress);
}
}
}
and then assign a CellFactory
to the second column 然后将CellFactory
分配给第二列
secondCol.setCellFactory(
new Callback<TreeTableColumn<Employee, String>, TreeTableCell<Employee, String>>() {
@Override
public TreeTableCell<Employee, String> call(
TreeTableColumn<Employee, String> param) {
return new ProgressCell();
}
});
where Employee
is the POJO class on which the TreeTableView is built 其中Employee
是构建TreeTableView的POJO类
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.