我试图将一个ComboBox放在一个表格单元格中,但我无法做到。代码是下一个:
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的TableColumn方法
答案 0 :(得分:5)
问题的一部分是您尝试将单元工厂设置为TableColumn
的单元值工厂字段。试试这个:
ObservableList<String> cbValues = FXCollections.observableArrayList("1", "2", "3");
TableColumn<Map, String> column2 = new TableColumn<>(Desglose2);
column2.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), cbValues));