JavaFX: Add UI control to TreeTableView

自古美人都是妖i 提交于 2019-11-27 04:54:12

问题


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?

Really appreciate any help!


回答1:


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.

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

and then assign a CellFactory to the second column

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



来源:https://stackoverflow.com/questions/26233554/javafx-add-ui-control-to-treetableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!