javafx - TreeView in a table cell Java FX 8 -


i have tableview in ui, displays user list database. 1 of column of table editable, when editing enabled cell of particular column becomes treeview, listing various options can chosen.

just clarify, trying implement datepicker or colorpicker functionality on table cell, own list of items tree.

the table defined this

private tableview<user> usertable; 

the particular column displays tree view defined this

private tablecolumn<user, treeview> col4; 

i set setcellfactory method display tree

col4.setcellfactory(new callback<tablecolumn<user,treeview>, tablecell<user,treeview>>() {              @override             public tablecell<user, treeview> call(                     tablecolumn<user, treeview> param)             {                 returns comboboxtablecell filled tree             }     }); 

in table, in corresponding column, when click cell, cell shows combo box , combobox on opening shows tree value.

however when cell in non-editable state, not sure how should set setcellvaluefactory string value

col4.setcellvaluefactory(new callback<tablecolumn.celldatafeatures<user,treeview>, observablevalue<treeview>>() {          @override         public observablevalue<treeview> call(                 celldatafeatures< user,treeview> param)         {                      }   } 

i want display value inside treeview string when cell in non editable state. @ loss how return observablevalue of type treeview per method signature , still display string.

you need distinguish between data tableview (and it's tablecolumns) presenting, , cells used present data. cellvaluefactory object determines how value (i.e. data) particular column value entire row. cellfactory object determines how cell presents data user.

any time write tablecolumn<user, treeview<...>> (almost always) mistake. first type in type parameters type of object in each row of table - fine here - , second type of data displayed. treeview not data type: it's type of ui element, i.e. type of used display data.

so want along these lines. (you haven't been specific in explaining data model - fine - might not quite right; give idea though.)

tableview<user> usertable ; tablecolumn<user, options> optionscol ; 

the user class have objectproperty<options>:

public class user {     private final objectproperty<options> options = new simpleobjectproperty<>(this, "options", new options());     public final options getoptions() {         return options.get();     }     public final void setoptions(options options) {         this.options.set(options);     }     public objectproperty<options> optionsproperty() {         return options ;     }      // other properties, etc... } 

and depends on options class encapsulating data displayed in column:

public class options {     // properties etc } 

now use default cell value factory:

optionscol.setcellvaluefactory(new propertyvaluefactory("options")); 

(or in javafx 8, prefer

    optionscol.setcellvaluefactory((tablecolumn.celldatafeatures<user, options> data) ->          data.getvalue()    // user object         .optionsproperty() // objectproperty<options>, observablevalue<options>     ); 

which more efficient avoids reflection propertyvaluefactory uses, , not more code, if omit type on parameter lambda expression).

(you don't have set this. if options not intrinsic part of user, could, example, have map<user, objectproperty<options>> defined , use return objectproperty<options> associated each user. way showed common , easiest way.)

i don't understand combobox fits in, answer should give enough work in need it. cellfactory has return tablecell uses treeview display options object:

optionscol.setcellfactory( col -> new tablecell<user, options>() {     private treeview<...> treeview ;     {         treeview = new treeview<>(...);         // configure tree view, etc     }     @override     public void updateitem(options options, boolean empty) {         super.updateitem(options, empty) ;         if (empty) {             setgraphic(null);         } else {             // configure treeview data options, etc             setgraphic(treeview);         }     } }); 

you mentioned cell editable, need wire editing stuff cell (and you'll want use named [inner] class it's going bit verbose, instead of anonymous inner class have here). should give basic structure.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -