javafx combobox在edit状态下无法选择
天蓬老师
天蓬老师 2017-04-18 10:50:03
0
0
763

javafx 中combobox设置成combobox.setEditable(true);combobox就无法选择,也获取不到选择了的值。请问有遇到这种情况的嘛?

下面是代码

private ComboBox peopleComBox; private ObservableList peopleComBoxData = FXCollections.observableArrayList(); public MainPageController() { peopleComBoxData.add(new SimpleStringProperty("HansMuster")); peopleComBoxData.add(new SimpleStringProperty("RuthMueller")); peopleComBoxData.add(new SimpleStringProperty("HeinzKurz")); } private void initialize() { peopleComBox.setItems(peopleComBoxData); peopleComBox.setEditable(true); // Define rendering of the list of values in ComboBox drop down. peopleComBox.setCellFactory((comboBox) -> { return new ListCell() { @Override protected void updateItem(StringProperty item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setText(null); } else { setText(item.get()); } } }; }); // Define rendering of selected value shown in ComboBox. peopleComBox.setConverter(new StringConverter() { @Override public String toString(StringProperty person) { if (person == null) { return null; } else { return person.get(); } } @Override public StringProperty fromString(String personString) { return null; // No conversion fromString needed. } }); }
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all (0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!