Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

java - 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. How would i accomplish something like this?

Really appreciate any help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...