arraylist - javafx tableview data from List -
i've got problem tableview in javafx.
creating tables existing class fields defined easy.
but i'm wondering if possible make table , add data list?
i've made kinda doesn't work.
@fxml private tableview<list<string>> testtable; .... list<string> list = new arraylist<>(); list.add("1hello"); list.add("1hello2"); list<string> list2 = new arraylist<>(); list2.add("2hello"); list2.add("2hello2"); observablelist<list<string>> lists = fxcollections.observablearraylist(); lists.add(list); lists.add(list2); tablecolumn<list<string>, string> coll = new tablecolumn<>("one"); coll.setcellvaluefactory(new propertyvaluefactory<list<string>,string>("")); tablecolumn<list<string>, string> coll2 = new tablecolumn<>("two"); coll2.setcellvaluefactory(new propertyvaluefactory<list<string>,string>("")); testtable.getcolumns().add(coll); testtable.getcolumns().add(coll2); lists.foreach(li -> { system.out.println("list: " + li); testtable.getitems().add(li); });
it didn't insert data. possible?
you can replacing string
stringproperty
in list
:
@fxml private tableview<list<stringproperty>> testtable;
then:
tablecolumn<list<stringproperty>, string> coll = new tablecolumn<>("one");
abd cellvaluefactories:
col1.setcellvaluefactory(data -> data.getvalue().get(0)); col2.setcellvaluefactory(data -> data.getvalue().get(1)); . .
and on.
this means first element of list used in col1
, second element of list used in col2
.
then can populate list like:
observablelist<list<stringproperty>> data = fxcollections.observablearraylist(); list<stringproperty> firstrow = new arraylist<>(); firstrow.add(0, new simplestringproperty("andrew")); firstrow.add(1, new simplestringproperty("smith")); . . . data.add(firstrow); . . . , on... table.setitems(data);
it doable way very bad practice.
Comments
Post a Comment