TableView insert data from list box javafx -


i have listbox populated data mysql database. wish add selected item in tableview listview. problem is, when click add button, selected item gets added in 1st cell. when select item click add, gets on written in 1st cell. here's code.

button select= new button("select"); private tableview table = new tableview<>(); public void start(stage primarystage) throws exception{ tablecolumn<map, string> namecol = new tablecolumn<>("namecol"); tablecolumn<map, string> quantitycol = new tablecolumn<>("quantity"); tablecolumn<map, string> pricecol = new tablecolumn<>("price"); observablelist <string> items = fxcollections.observablearraylist (         "0" , "1" , "2" , "3" , "4" ,               "5" , "6" , "7" , "8" , "9" );      table.getcolumns().addall(namecol, quantitycol, pricecol);      quantitycol.setcellfactory(choiceboxtablecell.fortablecolumn (items));     table.setitems(generatedatainmap());     table.seteditable(true);     table.getselectionmodel().setcellselectionenabled(true);     table.getcolumns().setall(namecol, quantitycol,pricecol);  select.setonaction(new eventhandler<actionevent>() {         @override         public void handle(actionevent e) {                try {                    table.setitems(generatedatainmap());                   namecol.setcellvaluefactory(new mapvaluefactory(column1mapkey));        } catch (exception ex) {            logger.getlogger(mainmenu.class.getname()).log(level.severe, null, ex);        }    }     });  private observablelist<map> generatedatainmap() {       int count = 1;      observablelist<map> alldata = fxcollections.observablearraylist();          map<string, string> datarow = new hashmap<>();         string value1 = nameview.getselectionmodel().getselecteditem();          datarow.put(column1mapkey, value1);          alldata.add(datarow);         system.out.println(datarow);     return alldata; }  public static void main(string[] args) {     launch(args);  } 

i haven't written code, code block. can please me out. i'll appreciate :) :)

in event handler calling

table.setitems(...); 

which sets items shown in table (i.e. replaces there ones specify).

use

table.getitems().addall(...); 

instead.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -