swing - Java - JTable show only last line from txt file -


i have txt file this:

user user 1||address1|telephonecall|x|drivingdepartment|vehicle|x user user 2||address2|telephonecall|x|drivingdepartment|vehicle|x user user 3||address3|telephonecall|x|drivingdepartment|vehicle|x user user 4||address4|telephonecall|x|drivingdepartment|vehicle|x 

and tried show in jtable this, it's show last line 4 time (as many how many lines in text file)

    public arraylist<voznje> ucitajvoznje() {         arraylist<voznje> zakazanevoznje = new arraylist<voznje>();         try {             file voznjefile = new file("src/txt/voznje");             bufferedreader br = new bufferedreader(new filereader(voznjefile));             string line = null;             while ((line = br.readline()) != null) {                 string[] split = line.split("\\|");                 string imeprezimemusterije = split[0];                 string datumpolaska = split[1];                 string adresapolaska = split[2];                 string nacinporudzbine = split[3];                 string vozac = split[4];                 string dispecer = split[5];                 string vrstavozila = split[6];                 string napomena = split[7];                  voznje novavoznja = new voznje(imeprezimemusterije, datumpolaska, adresapolaska, nacinporudzbine, vozac, dispecer, vrstavozila, napomena);                 zakazanevoznje.add(novavoznja);             }         } catch (exception e) {             e.printstacktrace();         }         //system.out.println(zakazanevoznje);         return zakazanevoznje;     }  private void initgui() {         arraylist<voznje> zakazanevoznje = ucitajvoznje();         string[] zaglavlje = new string[] {"musterija", "datum", "adresa", "rezervacija", "vozac", "dispecer", "vrsta vozila", "napomena"};         object[][] prikaz = new object[zakazanevoznje.size()][zaglavlje.length];             int = 0;         (int = 0; < zakazanevoznje.size(); i++){             (voznje v : zakazanevoznje) {                 prikaz[i][0] = v.getimeprezimemusterije();                 prikaz[i][1] = v.getdatumpolaska();                 prikaz[i][2] = v.getadresapolaska();                 prikaz[i][3] = v.getnacinporudzbine();                 prikaz[i][4] = v.getvozac();                 prikaz[i][5] = v.getdispecer();                 prikaz[i][6] = v.getvrstavozila();                 prikaz[i][7] = v.getnapomena();              }         }          defaulttablemodel tablemodel = new defaulttablemodel(prikaz,zaglavlje);         tblvoznje = new jtable(tablemodel);         tblvoznje.setrowselectionallowed(true);         tblvoznje.setcolumnselectionallowed(true);         tblvoznje.setselectionmode(listselectionmodel.single_selection);         tblvoznje.setdefaulteditor(object.class, null);          jscrollpane tablescroll = new jscrollpane(tblvoznje);         add(spskrol);         add(tbtulbar, borderlayout.north);         add(tablescroll, borderlayout.center); 

of course, want show every single line, it's looks this... : enter image description here

i suppse problem somewhere loop...

its because filling data subjects on every iteration

for (int = 0; < zakazanevoznje.size(); i++){     (voznje v : zakazanevoznje) { // here mistake         prikaz[i][0] = v.getimeprezimemusterije();         prikaz[i][1] = v.getdatumpolaska();         prikaz[i][2] = v.getadresapolaska();         prikaz[i][3] = v.getnacinporudzbine();         prikaz[i][4] = v.getvozac();         prikaz[i][5] = v.getdispecer();         prikaz[i][6] = v.getvrstavozila();         prikaz[i][7] = v.getnapomena();      } } 

it should

for (int = 0; < zakazanevoznje.size(); i++){     voznje v=zakazanevoznje.get(i)         prikaz[i][0] = v.getimeprezimemusterije();         prikaz[i][1] = v.getdatumpolaska();         prikaz[i][2] = v.getadresapolaska();         prikaz[i][3] = v.getnacinporudzbine();         prikaz[i][4] = v.getvozac();         prikaz[i][5] = v.getdispecer();         prikaz[i][6] = v.getvrstavozila();         prikaz[i][7] = v.getnapomena(); } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -