binding - Javafx combobox bound value cannot be set exception -


i'm using trying use javafx combobox cell factory render list, using settext on override updateitem() of celllist, found out when change value on underlying model, doesnẗ afects deployed list on combo box. try make binding both properties , it's works when try clear selection have exception. code:

    import javafx.application.application; import javafx.beans.property.simplestringproperty; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.stage; import javafx.util.callback;  public class basiccomboboxsample extends application {     public static void main(string[] args) { launch(args); }      @override public void start(stage stage) {         final employee john = new employee("john");         final employee jill = new employee("jill");         final employee jack = new employee("jack");          final combobox<employee> cboemployees = new combobox();          cboemployees.getitems().addall(john, jill, jack);         cboemployees.setvalue(jill);          button b = new button("changename");         b.setonaction(new eventhandler<actionevent>() {             @override             public void handle(actionevent actionevent) {                 john.setname("maria");             }         });          button c = new button("clear");         c.setonaction(new eventhandler<actionevent>() {             @override             public void handle(actionevent actionevent) {                 cboemployees.getselectionmodel().clearselection();             }         });          button d = new button("select first");         d.setonaction(new eventhandler<actionevent>() {             @override             public void handle(actionevent actionevent) {                 cboemployees.getselectionmodel().select(john);             }         });          callback<listview<employee>, listcell<employee>> cellfactory = new callback<listview<employee>, listcell<employee>>() {             @override             public listcell<employee> call(listview<employee> listview) {                 return new employeelistcell();  //to change body of implemented methods use file | settings | file templates.             }         };          cboemployees.setbuttoncell(new employeelistcell());         cboemployees.setcellfactory(cellfactory);          final stackpane layout = new stackpane();         vbox v = new vbox();          v.getchildren().add(cboemployees);         v.getchildren().add(b);         v.getchildren().add(c);         v.getchildren().add(d);         layout.getchildren().add(v);          layout.setstyle("-fx-background-color: cornsilk; -fx-padding: 15;");         stage.setscene(new scene(layout));         stage.show();     }      class employee {         public employee(string name) { this.setname(name); }         private simplestringproperty name = new simplestringproperty("");          string getname() {             return name.get();         }          simplestringproperty nameproperty() {             return name;         }          void setname(string name) {             this.name.set(name);         }     }       public class employeelistcell extends listcell<employee> {          @override         protected void updateitem(employee emp, boolean b) {             super.updateitem(emp, b);             if(emp != null){                 textproperty().bind(emp.nameproperty());             }         }     } } 

and exception was:

exception in thread "javafx application thread" java.lang.runtimeexception: bound value cannot set. @ javafx.beans.property.stringpropertybase.set(stringpropertybase.java:157) @ javafx.beans.property.stringpropertybase.set(stringpropertybase.java:67) @ javafx.beans.property.stringproperty.setvalue(stringproperty.java:84) @ javafx.scene.control.labeled.settext(labeled.java:135) @ com.sun.javafx.scene.control.skin.comboboxlistviewskin.updatedisplaytext(comboboxlistviewskin.java:420) @ com.sun.javafx.scene.control.skin.comboboxlistviewskin.updatedisplaynode(comboboxlistviewskin.java:399) @ com.sun.javafx.scene.control.skin.comboboxlistviewskin.getdisplaynode(comboboxlistviewskin.java:229) @ com.sun.javafx.scene.control.skin.comboboxbaseskin.updatedisplayarea(comboboxbaseskin.java:125) @ com.sun.javafx.scene.control.skin.comboboxbaseskin.handlecontrolpropertychanged(comboboxbaseskin.java:120) @ com.sun.javafx.scene.control.skin.comboboxlistviewskin.handlecontrolpropertychanged(comboboxlistviewskin.java:198) @ com.sun.javafx.scene.control.skin.skinbase$3.changed(skinbase.java:282) @ javafx.beans.value.weakchangelistener.changed(weakchangelistener.java:107) @ com.sun.javafx.binding.expressionhelper$generic.firevaluechangedevent(expressionhelper.java:367) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:100) @ javafx.beans.property.objectpropertybase.firevaluechangedevent(objectpropertybase.java:123) @ javafx.beans.property.objectpropertybase.markinvalid(objectpropertybase.java:130) @ javafx.beans.property.objectpropertybase.set(objectpropertybase.java:163) @ javafx.scene.control.comboboxbase.setvalue(comboboxbase.java:148) @ javafx.scene.control.combobox.updatevalue(combobox.java:416) @ javafx.scene.control.combobox.access$300(combobox.java:166) @ javafx.scene.control.combobox$6.changed(combobox.java:401) @ com.sun.javafx.binding.expressionhelper$generic.firevaluechangedevent(expressionhelper.java:367) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:100) @ javafx.beans.property.readonlyobjectwrapper$readonlypropertyimpl.firevaluechangedevent(readonlyobjectwrapper.java:195) @ javafx.beans.property.readonlyobjectwrapper.firevaluechangedevent(readonlyobjectwrapper.java:161) @ javafx.beans.property.objectpropertybase.markinvalid(objectpropertybase.java:130) @ javafx.beans.property.objectpropertybase.set(objectpropertybase.java:163) @ javafx.scene.control.selectionmodel.setselecteditem(selectionmodel.java:101) @ javafx.scene.control.combobox$comboboxselectionmodel$1.invalidated(combobox.java:448) @ com.sun.javafx.binding.expressionhelper$singleinvalidation.firevaluechangedevent(expressionhelper.java:155) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:100) @ javafx.beans.property.readonlyintegerwrapper$readonlypropertyimpl.firevaluechangedevent(readonlyintegerwrapper.java:195) @ javafx.beans.property.readonlyintegerwrapper.firevaluechangedevent(readonlyintegerwrapper.java:161) @ javafx.beans.property.integerpropertybase.markinvalid(integerpropertybase.java:130) @ javafx.beans.property.integerpropertybase.set(integerpropertybase.java:163) @ javafx.scene.control.selectionmodel.setselectedindex(selectionmodel.java:67) @ javafx.scene.control.singleselectionmodel.updateselectedindex(singleselectionmodel.java:208) @ javafx.scene.control.singleselectionmodel.clearselection(singleselectionmodel.java:67) @ de.thomasbolz.javafx.basiccomboboxsample$2.handle(basiccomboboxsample.java:45) @ de.thomasbolz.javafx.basiccomboboxsample$2.handle(basiccomboboxsample.java:42) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:69) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:217) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:170) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:38) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:37) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:35) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:53) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:28) @ javafx.event.event.fireevent(event.java:171) @ javafx.scene.node.fireevent(node.java:6863) @ javafx.scene.control.button.fire(button.java:179) @ com.sun.javafx.scene.control.behavior.buttonbehavior.mousereleased(buttonbehavior.java:193) @ com.sun.javafx.scene.control.skin.skinbase$4.handle(skinbase.java:336) @ com.sun.javafx.scene.control.skin.skinbase$4.handle(skinbase.java:329) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:64) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:217) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:170) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:38) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:37) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:35) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:35) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:53) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:33) @ javafx.event.event.fireevent(event.java:171) @ javafx.scene.scene$mousehandler.process(scene.java:3328) @ javafx.scene.scene$mousehandler.process(scene.java:3168) @ javafx.scene.scene$mousehandler.access$1900(scene.java:3123) @ javafx.scene.scene.impl_processmouseevent(scene.java:1563) @ javafx.scene.scene$scenepeerlistener.mouseevent(scene.java:2265) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:250) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:173) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(glassvieweventhandler.java:292) @ com.sun.glass.ui.view.handlemouseevent(view.java:528) @ com.sun.glass.ui.view.notifymouse(view.java:922) @ com.sun.glass.ui.gtk.gtkapplication._runloop(native method) @ com.sun.glass.ui.gtk.gtkapplication$3$1.run(gtkapplication.java:82) @ java.lang.thread.run(thread.java:722) 

you need unbind textproperty in case emp null


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -