【发布时间】:2018-11-09 07:02:05
【问题描述】:
我有一个带有 id 和名称的模型。 I put the model object into a combobox. From the model i take the name atribute and make that the visual part, the only problem is. When you start up the 将组合框编程为空。 您必须单击它并选择第二行才能看到该项目。我想立即查看该项目。这可能吗?
public class ItemCell extends ListCell<Model> {
@Override
public void updateItem(Model person, boolean empty) {
super.updateItem(person, empty);
setText(person == null ? "" : person.getFirstName());
}
}
在我的视图类中,我有:
ComboBox<Model> comboBox = new ComboBox<>();
comboBox.setCellFactory(lv -> new ItemCell());
comboBox.setButtonCell(new ItemCell());
comboBox.valueProperty().addListener((o, oldValue, newValue) -> {
personModelFromCombobox = otherObject.getPerson();
});
正如您所见,一切都是正确的,只是您必须单击它并选择第二行才能看到该项目。
【问题讨论】: