JavaFX TableView controls are not repainted correctly after remove item / add new item -


i using observablelist control items , every time delete item, tableview removes datasource. the view not being updated i'm still seeing items. difference removed item can not selected anymore.

similar problem: javafx listview , treeview controls not repainted correctly

in following code:

final tablecolumn<tmachinetype, string> testertype = new tablecolumn<tmachinetype, string>(             bundle.getstring("table.testertype"));      testertype             .setcellvaluefactory(new propertyvaluefactory<tmachinetype, string>(                     "testertype"));      testertype             .setcellfactory(new callback<tablecolumn<tmachinetype, string>, tablecell<tmachinetype, string>>() {                  @override                 public tablecell<tmachinetype, string> call(                         final tablecolumn<tmachinetype, string> param) {                     final tablecell<tmachinetype, string> cell = new tablecell<tmachinetype, string>() {                         @override                         protected void updateitem(final string item,                                 final boolean empty) {                             super.updateitem(item, empty);                             textproperty().unbind();                             if (empty || item == null) {                                 setgraphic(null);                                 settext(null);                             }                             if (!empty) {                                     final tmachinetype row = (tmachinetype) gettablerow().getitem();                                     textproperty().bind(                                             row.testertypeproperty());                                 }                          }                     };                     return cell;                 }             }); 

tmachinetype class:

private final simplestringproperty testertype = new simplestringproperty();      @column(name = "tester_type") public string gettestertype() {     return testertype.get(); }  public void settestertype(string testertype) {     this.testertype.set(testertype); }  public stringproperty testertypeproperty() {     return testertype; } 

observable list: 1. db entities:

final query q = em.createquery("select t tmachinetype t"); final list resultlist = q.getresultlist(); 

2. obs. list setup:

    observablelist<tmachinetype> observablelist; ...     observablelist = fxcollections.observablearraylist(resultlist);     tablemachinetype.setitems(observablelist);     fxcollections.sort(observablelist); 
  1. row removal:

    @fxml private void handleonremove(final actionevent event) {  final observablelist<tmachinetype> selectedindices = tablemachinetype         .getselectionmodel().getselecteditems(); final string infotxt = selectedindices.size() + " "         + bundle.getstring("message.records_removed");  final list<tmachinetype> deletebuffer = new arraylist<tmachinetype>(); deletebuffer.addall(selectedindices);  (final tmachinetype selectedidx : deletebuffer) {      selectedidx.manufacturerproperty().unbind();     selectedidx.testertypeproperty().unbind();      deleted.add(selectedidx);     observablelist.remove(selectedidx);     // tablemachinetype.getitems().remove(selectedidx);  } .. 

    }

removing cellfactory fix problem ! yehu :)

testertype         .setcellfactory(new callback<tablecolumn<tmachinetype, string>, tablecell<tmachinetype, string>>() {              @override             public tablecell<tmachinetype, string> call(                     final tablecolumn<tmachinetype, string> param) {                 final tablecell<tmachinetype, string> cell = new tablecell<tmachinetype, string>() {                     @override                     protected void updateitem(final string item,                             final boolean empty) {                         super.updateitem(item, empty);                         textproperty().unbind();                         if (empty || item == null) {                             setgraphic(null);                             settext(null);                         }                         if (!empty) {                                 final tmachinetype row = (tmachinetype) gettablerow().getitem();                                 textproperty().bind(                                         row.testertypeproperty());                             }                      }                 };                 return cell;             }         }); 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -