本文介绍了如何将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的TableColumn方法
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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!