java - JavaFX 2 - Tableview Checkbox not showing value -
i managed track whenever click happens on checkbox in gui. won't load correct value of checkbox gui. can see might wrong? :)
roadtraincol.setcellvaluefactory( new callback<celldatafeatures<spot,boolean>,observablevalue<boolean>>() { public observablevalue<boolean> call(celldatafeatures<spot, boolean> param) { return param.getvalue().getroadtrain(); } }); roadtraincol.setcellfactory(col -> { checkboxtablecell<spot, boolean> cell = new checkboxtablecell<>(index -> { booleanproperty active = new simplebooleanproperty(); active.addlistener((obs, wasactive, isnowactive) -> { system.out.println("del"); rettedespots(tableviewid.getitems().get(index).getid()); }); return active ; }); return cell ; });
you're creating new booleanproperty
s. properties initialized false
.
the cellfactory
not place add listeners. add listeners items instead.
roadtraincol.setcellvaluefactory( new callback<celldatafeatures<spot, boolean>, observablevalue<boolean>>() { public observablevalue<boolean> call(celldatafeatures<spot, boolean> param) { return param.getvalue().getroadtrain(); } }); roadtraincol.setcellfactory(checkboxtablecell.fortablecolumn(roadtraincol)); changelistener<boolean> roadtrainchangelistener = (observable, oldvalue, newvalue) -> { spot spot = (spot) ((readonlyproperty) observable).getbean(); system.out.println("del"); rettedespots(spot.getid()); }; // add/remove listeners when spots added to/removed list tableviewid.getitems().addlistener((listchangelistener.change<? extends spot> c) -> { while (c.next()) { (spot s : c.getremoved()) { s.getroadtrain().removelistener(roadtrainchangelistener); } (spot s : c.getaddedsublist()) { s.getroadtrain().addlistener(roadtrainchangelistener); } } }); // add listeners items in list (spot s : tableviewid.getitems()) { s.getroadtrain().addlistener(roadtrainchangelistener); }
note works, if assigned spot
instance containing simplebooleanproperty
bean
, e.g.
spot() { this.roadtrain = new simplebooleanproperty(this, "roadtrain"); }
or
spot(boolean roadtrain) { this.roadtrain = new simplebooleanproperty(this, "roadtrain", roadtrain); }
i used bean
avoid having tho create new listeners every item.
also consider following naming conventions javafx properties:
- property getter named
<propertyname>property
(notget<capitalfirstletterpropertyname>
) - the getter property's value named
get<capitalfirstletterpropertyname>
- the setter property's value named
set<capitalfirstletterpropertyname>
Comments
Post a Comment