[英]JavaFX: Add UI control to TreeTableView
假設我在TreeTableView中有2列,現在我想在第一列中添加一個字符串/標簽,在另一列中添加一個ProgressBar。 我將如何完成這樣的事情?
非常感謝任何幫助!
正如James_D正確指出的那樣,您可以將ProgressBarTreeTableCell
用於帶有ProgressBars的列。 內部支持其他一些UI控件,例如TextField
, CheckBox
等。
對於其他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);
}
}
}
然后將CellFactory
分配給第二列
secondCol.setCellFactory(
new Callback<TreeTableColumn<Employee, String>, TreeTableCell<Employee, String>>() {
@Override
public TreeTableCell<Employee, String> call(
TreeTableColumn<Employee, String> param) {
return new ProgressCell();
}
});
其中Employee
是構建TreeTableView的POJO類
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.