从单元格内部获取TreeTableView行?

时间:2018-01-25 09:29:13

标签: java javafx

thisColumn.setCellFactory(new Callback<TreeTableColumn<Obj, String>, TreeTableCell<Obj, String>>() {
    @Override
    public TreeTableCell<Task, String> call(final TreeTableColumn<Task, String> param) {
        JFXComboBox<String> jfxComboBox = new JFXComboBox<>();
        jfxComboBox.setMinWidth(100.0);
        jfxComboBox.setPrefWidth(100.0);
        jfxComboBox.setItems(Class.profiles);

        jfxComboBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                /** N/A **/
            }
        });
        final TreeTableCell<Task, Void> cell = new TreeTableCell<Task, Void>() {
            HBox hBox = new HBox();
            Boolean result = hBox.getChildren().addAll(jfxComboBox);
            @Override
            public void updateItem(Void item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setGraphic(null);
                } else {
                    setGraphic(hBox);
                }
            }
        };
        return cell;
    }
});

我目前正在尝试在TreeTableView中显示JFXComboBox(ComboBox),并使用当前代码添加它。但是,在回调中,我无法访问jfxComboBox所在的行。

我注意到,如果我使用TreeTableColumn.CellDataFeatures而不是TreeTableColumn,它会让我访问param.getValue()。getValue()这正是我需要的,但是之后我就可以了无法返回TreeTableCell以显示我的jfxComboBox。

关于如何实现这一目标的任何建议?

PS:

我试图避免使用.getSelectionModel().getSelectedItem(),因为当我点击ComboBox时,我还没有选择当前行/可能在点击组合框之前没有选择任何行。但是我有兴趣看看是否有一种方法可以触发jfxComboBox所在的父行的选择。

1 个答案:

答案 0 :(得分:2)

可以解决您问题的示例:

StatusBarItem logo = new StatusBarItem
{
    Content = new Image
    {
        Source = new BitmapImage(new Uri("logo.ico", UriKind.Relative)),
        Width = 16,
        Height = 16
    }
};
Grid.SetColumn(logo, 2);
StatusBarItemsSource.Add(logo);
相关问题