如何将 ComboBoxTableCell 放在 TableView 中? [英] How to put ComboBoxTableCell in a TableView?

查看:22
本文介绍了如何将 ComboBoxTableCell 放在 TableView 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 ComboBox 放入表格单元格中,但我不能.代码是下一个:

I'm trying to put a ComboBox in a table cell, but I can't. the code is the next:

private void cargaTablaDesglose() {
    TableColumn<Map, String> column1 = new TableColumn<>(Desglose1);
    TableColumn<Map, String> column2 = new TableColumn<>(Desglose2);
    TableColumn<Map, String> column3 = new TableColumn<>(Desglose3);

    column1.setCellValueFactory(new MapValueFactory(Desglose1));
    column1.setMaxWidth(0);
    column2.setCellValueFactory(new ComboBoxTableCell.forTableColumn(null));
    column2.setPrefWidth(150);
    column3.setCellValueFactory(new MapValueFactory(Desglose3));
    column3.setPrefWidth(250);

    if (CUOD.modifyData()) {
        column2.setOnEditCommit((TableColumn.CellEditEvent<Map, String> t) -> {
            actualizaObra(t.getRowValue(), t.getNewValue());
        });
            }

    tablaDesglose.getItems().clear();
    tablaDesglose.setEditable(true);
    tablaDesglose.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    tablaDesglose.getSelectionModel().setCellSelectionEnabled(false);
    tablaDesglose.getColumns().clear();
    tablaDesglose.getColumns().addAll(column1, column2, column3);

    Callback<TableColumn<Map, String>, TableCell<Map, String>> cellFactoryMap
            = CUCF.getFactoryMap();
    column1.setCellFactory(cellFactoryMap);
    column2.setCellFactory(cellFactoryMap);
    column3.setCellFactory(cellFactoryMap);
}

它说找不到 ComboBoxTableCell 的 forTableColumn 方法

It says that can't found forTableColumn method of ComboBoxTableCell

推荐答案

问题的一部分是您试图将单元工厂设置为 TableColumn 的单元格值工厂字段.试试这个:

The part of the problem is that you're trying to set cell factory into cell value factory field of TableColumn. Try this instead:

ObservableList<String> cbValues = FXCollections.observableArrayList("1", "2", "3");

TableColumn<Map, String> column2 = new TableColumn<>(Desglose2);
column2.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), cbValues));

这篇关于如何将 ComboBoxTableCell 放在 TableView 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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