java - How to bind a JavaFX Label to the selected item from a ListView -


i have listview full of pojos , want label in gui display informations selected item.

my pojo looks that:

class customer {   private string name;   ...   public string getname() {   return name;    } 

now when user selects customer list want name of selected customer displayed in label.

obviously can't bind name directly because not property. (and don't want replace customers strings stringproperty-objects because simplestringproperty not serializable , need customer transfered via rmi.)

i've tried beanpathadapter jfxtras (which looks nice way) this:

    beanpathadapter<multipleselectionmodel> customerbeanpathadapter;     customerbeanpathadapter = new beanpathadapter<>(lstcustomers.getselectionmodel());     customerbeanpathadapter.bindbidirectional("selecteditem.name", lblcustomername.textproperty()); 

but solution throws me exception:

... caused by: java.lang.illegalargumentexception: unable resolve accessor getselecteditem @ jfxtras.labs.scene.control.beanpathadapter$fieldhandle.buildaccessor(beanpathadapter.java:3062) @ jfxtras.labs.scene.control.beanpathadapter$fieldhandle.buildaccessorwithlikelyprefixes(beanpathadapter.java:3022) @ jfxtras.labs.scene.control.beanpathadapter$fieldhandle.updatemethodhandles(beanpathadapter.java:2986) @ jfxtras.labs.scene.control.beanpathadapter$fieldhandle.<init>(beanpathadapter.java:2977) @ jfxtras.labs.scene.control.beanpathadapter$fieldbean.performoperation(beanpathadapter.java:1348) @ jfxtras.labs.scene.control.beanpathadapter$fieldbean.performoperation(beanpathadapter.java:1186) @ jfxtras.labs.scene.control.beanpathadapter.bindbidirectional(beanpathadapter.java:567) @ jfxtras.labs.scene.control.beanpathadapter.bindbidirectional(beanpathadapter.java:369) @ at.gs1.sync.qm.client.gui.mainwindowcontroller.initialize(mainwindowcontroller.java:61) ... 22 more caused by: java.lang.illegalaccessexception: symbolic reference class not public: class javafx.scene.control.listview$listviewbitsetselectionmodel, jfxtras.labs.scene.control.beanpathadapter$fieldhandle @ java.lang.invoke.membername.makeaccessexception(membername.java:512) @ java.lang.invoke.methodhandles$lookup.checksymbolicclass(methodhandles.java:1113) @ java.lang.invoke.methodhandles$lookup.resolveorfail(methodhandles.java:1094) @ java.lang.invoke.methodhandles$lookup.findvirtual(methodhandles.java:626) @ jfxtras.labs.scene.control.beanpathadapter$fieldhandle.buildaccessor(beanpathadapter.java:3049) ... 30 more 

so hoped there better solution use lstcustomers.getselectionmodel().selecteditemproperty().addlistener(...) , handle population of labels there manually.

a better solution think, 1 gave before, use beanpathadapter tried.
beanpathadapter needs have following property added it:

private final objectproperty<b>  beanprop = new simpleobjectproperty<>(); {     beanprop.addlistener( new changelistener<b>()     {         @override         public void changed( observablevalue<? extends b> ob, b oldval, b newval )         {             setbean( newval );         }     } ); }  public objectproperty<b> beanproperty() {     return beanprop;  } 

then in code need following:

beanpathadapter<customer>  custbean; custbean = new beanpathadapter<>( new customer() );   // empty or customer custbean.bindbidirectional( "name", label.textproperty() ); custbean.beanproperty().bind( listview.getselectionmodel().selecteditemproperty() ); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -