JavaFX:向 TreeTableView 添加 UI 控件 [英] JavaFX: Add UI control to TreeTableView

查看:32
本文介绍了JavaFX:向 TreeTableView 添加 UI 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 TreeTableView 中有 2 列,现在我想在第一列中添加一个字符串/标签,在另一列中添加一个 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 用于带有 ProgressBar 的列.内部支持一些其他 UI 控件,例如 TextFieldCheckBox 等.

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();
                }
});

其中 Employee 是构建 TreeTableView 的 POJO 类

where Employee is the POJO class on which the TreeTableView is built

这篇关于JavaFX:向 TreeTableView 添加 UI 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆