【发布时间】:2018-05-21 12:21:40
【问题描述】:
我已经用组合框构建了 GUI。我有ObservableList<SimpleTableObject> types
应该显示材料的类型。看起来是这样的
material_comboBox_type.getItems().addAll(types);
material_comboBox_type.setCellFactory((ListView<SimpleTableObject>
param) -> {
final ListCell<SimpleTableObject> cell = new
ListCell<SimpleTableObject>() {
@Override
public void updateItem(SimpleTableObject item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setText(item.getName().get());//return String, actuall name of material
}
else {
setText(null);
}
}
};
return cell;
});
现在的问题是:当我单击组合框时,它会根据需要显示名称。但是当我选择一个而不是字符串属性时,会显示一个对象本身,看起来像classes.SimpleTableObject@137ff5c。
我怎样才能实现它?
【问题讨论】:
标签: javafx combobox observablecollection