java - Has anyone succeeded in autocomplete ComboBox for list cell? -
as standalone element, this solution works fine.
but in custom listcell (mirrored comboboxlistcell sources), gives sometimes:
exception in thread "javafx application thread" java.lang.nullpointerexception @ com.sun.javafx.scene.control.skin.comboboxpopupcontrol.positionandshowpopup(comboboxpopupcontrol.java:100) @ com.sun.javafx.scene.control.skin.comboboxpopupcontrol.show(comboboxpopupcontrol.java:74) @ com.sun.javafx.scene.control.skin.comboboxbaseskin.handlecontrolpropertychanged(comboboxbaseskin.java:115) @ com.sun.javafx.scene.control.skin.comboboxlistviewskin.handlecontrolpropertychanged(comboboxlistviewskin.java:245) @ com.sun.javafx.scene.control.skin.behaviorskinbase$2.call(behaviorskinbase.java:189) @ com.sun.javafx.scene.control.skin.behaviorskinbase$2.call(behaviorskinbase.java:187) @ com.sun.javafx.scene.control.multiplepropertychangelistenerhandler$1.changed(multiplepropertychangelistenerhandler.java:55) @ javafx.beans.value.weakchangelistener.changed(weakchangelistener.java:89) @ com.sun.javafx.binding.expressionhelper$singlechange.firevaluechangedevent(expressionhelper.java:176) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:80) @ javafx.beans.property.readonlybooleanwrapper$readonlypropertyimpl.firevaluechangedevent(readonlybooleanwrapper.java:178) @ javafx.beans.property.readonlybooleanwrapper$readonlypropertyimpl.access$100(readonlybooleanwrapper.java:148) @ javafx.beans.property.readonlybooleanwrapper.firevaluechangedevent(readonlybooleanwrapper.java:144) @ javafx.beans.property.booleanpropertybase.markinvalid(booleanpropertybase.java:110) @ javafx.beans.property.booleanpropertybase.set(booleanpropertybase.java:143) @ javafx.scene.control.comboboxbase.setshowing(comboboxbase.java:202) @ javafx.scene.control.comboboxbase.show(comboboxbase.java:407)
seems show() method combobox can produce npe inside javafx code.
custom comboboxlistcell differs in startedit():
@override public void startedit() { if (! iseditable() || ! getlistview().iseditable()) { return; } if (combobox == null) { combobox = createcombobox(this, items, converterproperty()); //the special string handler = new autocompletecomboboxlistener<>(combobox); combobox.editableproperty().bind(comboboxeditableproperty()); } combobox.getselectionmodel().select(getitem()); super.startedit(); if (isediting()) { settext(null); setgraphic(combobox); } }
code of autocompletecomboboxlistener gives npe:
@override public void handle(keyevent event) { if(event.getcode() == keycode.up) { caretpos = -1; movecaret(combobox.geteditor().gettext().length()); return; } else if(event.getcode() == keycode.down) { if(!combobox.isshowing()) { combobox.show(); } caretpos = -1; movecaret(combobox.geteditor().gettext().length()); return; } else if(event.getcode() == keycode.back_space) { movecarettopos = true; caretpos = combobox.geteditor().getcaretposition(); } else if(event.getcode() == keycode.delete) { movecarettopos = true; caretpos = combobox.geteditor().getcaretposition(); } if (event.getcode() == keycode.right || event.getcode() == keycode.left || event.iscontroldown() || event.getcode() == keycode.home || event.getcode() == keycode.end || event.getcode() == keycode.tab) { return; } observablelist list = fxcollections.observablearraylist(); (int i=0; i<data.size(); i++) { if(data.get(i).tostring().tolowercase().startswith( autocompletecomboboxlistener.this.combobox .geteditor().gettext().tolowercase())) { list.add(data.get(i)); } } string t = combobox.geteditor().gettext(); combobox.setitems(list); combobox.geteditor().settext(t); if(!movecarettopos) { caretpos = -1; } movecaret(t.length()); if(!list.isempty()) { //this gives npe inside javafx api combobox.show(); } }
ok, problem setitems skips current selection -1, , listcell treat fact if new value (null) needs committed (if current selection != -1). , after commit there nothing show combobox cause it's in non editing state.
so it's design issue, not bug. comboboxlistcell code not able change items on-the-fly without special care.
Comments
Post a Comment