java - JavaFX 8 - How to bind TextField text property to TableView integer property -
let's have situation this: have tableview (tableauthors) 2 tablecolumns (id , name).
this authorprops pojo used tableview:
import javafx.beans.property.simpleintegerproperty; import javafx.beans.property.simplestringproperty; public class authorprops { private final simpleintegerproperty authorsid; private final simplestringproperty authorsname; public authorprops(int authorsid, string authorsname) { this.authorsid = new simpleintegerproperty(authorsid); this.authorsname = new simplestringproperty( authorsname); } public int getauthorsid() { return authorsid.get(); } public simpleintegerproperty authorsidproperty() { return authorsid; } public void setauthorsid(int authorsid) { this.authorsid.set(authorsid); } public string getauthorsname() { return authorsname.get(); } public simplestringproperty authorsnameproperty() { return authorsname; } public void setauthorsname(string authorsname) { this.authorsname.set(authorsname); } } and let's have 2 textfields (txtid , txtname). now, bind values table cells textfields.
tableauthors.getselectionmodel() .selecteditemproperty() .addlistener((observablevalue, authorprops, authorprops2) -> { //this works: txtname.textproperty().bindbidirectional(authorprops2.authorsnameproperty()); //this doesn't work: txtid.textproperty().bindbidirectional(authorprops2.authorsidproperty()); }); i can bind name tablecolumn txtname textfield because authorsnameproperty simplestringproperty, can't bind id tablecolumn txtid textfield because authorsidproperty simpleintegerproperty. question is: how can bind txtid id tablecolumn?
p.s. can provide working example if it's necessary.
try:
txtid.textproperty().bindbidirectional(authorprops2.authorsidproperty(), new numberstringconverter());
Comments
Post a Comment