问题描述
假设我在TreeTableView中有2列,现在我想在第一列中添加字符串/ Label,在另一列中添加ProgressBar。我将如何完成这样的事情?
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. How would i accomplish something like this?
非常感谢任何帮助!
推荐答案
正如James_D所正确指出的,您可以使用 ProgressBarTreeTableCell
带有ProgressBars的列。其他一些UI控件有内部支持,例如 TextField
, CheckBox
等。
As correctly pointed out by James_D, you can use ProgressBarTreeTableCell
for a column with ProgressBars. There is internal supports for some other UI controls such as TextField
, CheckBox
etc.
对于其他UI控件,您可以创建自定义 TreeTableCell
,如下所示:
For other UI controls you can create a Custom TreeTableCell
as shown:
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);
}
}
}
然后分配一个 CellFactory
到第二列
secondCol.setCellFactory(
new Callback<TreeTableColumn<Employee, String>, TreeTableCell<Employee, String>>() {
@Override
public TreeTableCell<Employee, String> call(
TreeTableColumn<Employee, String> param) {
return new ProgressCell();
}
});
其中员工
是POJO类,其中TreeTableView已构建
where Employee
is the POJO class on which the TreeTableView is built
这篇关于JavaFX:将UI控件添加到TreeTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!