我有这个型号:
public class AbstractMappingRow {
private StringProperty abstractService = new SimpleStringProperty();
private StringProperty taskId = new SimpleStringProperty();
private StringProperty taskName = new SimpleStringProperty();
public AbstractMappingRow(String taksNameString, String taskIdString, String abstractServiceString) {
super();
this.abstractService = new SimpleStringProperty(abstractServiceString);
this.taskId = new SimpleStringProperty(taskIdString);
this.taskName = new SimpleStringProperty(taksNameString);
}
public StringProperty getAbstractService() {
return abstractService;
}
public void setAbstractService(StringProperty abstractService) {
this.abstractService = abstractService;
}
public StringProperty getTaskId() {
return taskId;
}
public void setTaskId(StringProperty taskId) {
this.taskId = taskId;
}
public StringProperty getTaskName() {
return taskName;
}
public void setTaskName(StringProperty taskName) {
this.taskName = taskName;
}
}
我正在尝试使用表格行[String - String - 带有字符串的ComboBox]。所以我设置了这样的表:
TableColumn<AbstractMappingRow,String> taskIdCol = new TableColumn<>("Task ID");
taskIdCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<AbstractMappingRow, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<AbstractMappingRow, String> p) {
return p.getValue().getTaskId();
}
});
mappingTable.getColumns().add(taskIdCol);
TableColumn<AbstractMappingRow,String> taskNameCol = new TableColumn<>("Task Name");
taskNameCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<AbstractMappingRow, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<AbstractMappingRow, String> p) {
return p.getValue().getTaskName();
}
});
mappingTable.getColumns().add(taskNameCol);
TableColumn<AbstractMappingRow, String> abstractServiceCol = new TableColumn<>("Abstrakter Dienst");
abstractServiceCol.setMinWidth( 200 );
abstractServiceCol.setCellValueFactory(cellData -> cellData.getValue().getAbstractService());
abstractServiceCol.setCellFactory(ComboBoxTableCell.<AbstractMappingRow, String>forTableColumn(FXCollections.observableArrayList("1", "3")));
mappingTable.getColumns().add(abstractServiceCol);
mappingTable.getItems().add(new AbstractMappingRow("test", "test", "3"));
但结果是,我没有在第三列中看到任何应该包含值“1”和“3”的ComboBox。相反,我看到了这一点:
我错过了让ComboBox显示的内容?谢谢!
答案 0 :(得分:1)
我发现了错误:我忘了设置
mappingTable.setEditable(true);
谢谢!