0

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!

user3713080
  • 399
  • 4
  • 17
  • See http://stackoverflow.com/questions/16721380/javafx-update-progressbar-in-tableview-from-task which does the same for a `TableView` – James_D Oct 07 '14 at 14:01

1 Answers1

0

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

ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
  • 1
    Always check the [API](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/cell/ProgressBarTreeTableCell.html) first ;) – James_D Oct 07 '14 at 14:14
  • 1
    `ProgressBarTreeTableCell`, this is cool. Let the OP use this for those controls whose CellFactories are not provided by JavaFX ;-) – ItachiUchiha Oct 07 '14 at 14:26