java - Data does not appear in javafx Table View -


im trying make gui program using javafx. program supposed take data csv file, store in public list , display in javafx tableview in gui controller class.

here controller code

package controllers;  import java.io.ioexception; import java.net.url; import java.util.resourcebundle;   import javafx.collections.fxcollections; import javafx.collections.observablelist; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.fxml.fxmlloader; import javafx.fxml.initializable; import javafx.scene.parent; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.control.tablecolumn; import javafx.scene.control.tableview; import javafx.scene.control.cell.propertyvaluefactory; import javafx.stage.stage; import application.main; import application.tablaest;  public class controllerver1 implements initializable {      public stage stage = new stage();      private observablelist<tablaest> data = fxcollections.observablearraylist();      @fxml     private button volverbutton;      @fxml     private tableview<tablaest> tabledata;      //se crean columnas     @fxml     private tablecolumn<tablaest, string> namecol;     @fxml     private tablecolumn<tablaest, string> matcol;     @fxml     private tablecolumn<tablaest, string> carcol;     @fxml     private tablecolumn<tablaest, string> ingcol;     @fxml     private tablecolumn<tablaest, string> promcol;     @fxml     private tablecolumn<tablaest, string> estcol;      @override     public void initialize(url location, resourcebundle resources) {          namecol.setcellvaluefactory(new propertyvaluefactory<tablaest,string>("nombre"));         matcol.setcellvaluefactory(new propertyvaluefactory<tablaest,string>("matrĂ­cula"));         carcol.setcellvaluefactory(new propertyvaluefactory<tablaest,string>("carrera"));         ingcol.setcellvaluefactory(new propertyvaluefactory<tablaest,string>("ingreso"));         promcol.setcellvaluefactory(new propertyvaluefactory<tablaest,string>("promedio"));         estcol.setcellvaluefactory(new propertyvaluefactory<tablaest,string>("estatus"));         tabledata.seteditable(true);         (int i=0; < (main.estudiantes).size(); i++){             data.add(new tablaest(                     (main.estudiantes).get(i)[0],                     (main.estudiantes).get(i)[1],                     (main.estudiantes).get(i)[2],                     (main.estudiantes).get(i)[3],                     (main.estudiantes).get(i)[4],                     (main.estudiantes).get(i)[5]));             //for (int j=0; j<(main.estudiantes.get(i)).length; j++){             //}             system.out.println(data.get(i));         }         tabledata.setitems(data);     }      @fxml     public void volveramain(actionevent e) throws ioexception{         stage = (stage)volverbutton.getscene().getwindow();         parent root = fxmlloader.load(getclass().getresource("/application/maingui.fxml"));         scene scene = new scene(root);         stage.setscene(scene);         stage.show();     }  } 

here constructor class

package application;  import javafx.beans.property.simplestringproperty;  public class tablaest {     private final simplestringproperty name;     private final simplestringproperty mat;     private final simplestringproperty car;     private final simplestringproperty ing;     private final simplestringproperty prom;     private final simplestringproperty est;      public tablaest (string sname, string smat, string scar, string sing, string sprom, string sest) {         this.name = new simplestringproperty(sname);         this.mat = new simplestringproperty(smat);         this.car = new simplestringproperty(scar);         this.ing = new simplestringproperty(sing);         this.prom = new simplestringproperty(sprom);         this.est = new simplestringproperty(sest);     }      //getter methods     public string getname(){         return name.get();     }     public string getmat(){         return mat.get();     }     public string getcar(){         return car.get();     }     public string geting(){         return ing.get();     }     public string getprom(){         return prom.get();     }     public string getest(){         return est.get();     }      //setter methods     public void setname(string nname){         name.set(nname);     }     public void setmat(string nmat){         mat.set(nmat);     }     public void setcar(string ncar){         car.set(ncar);     }     public void seting(string ning){         ing.set(ning);     }     public void setprom(string nprom){         prom.set(nprom);     }     public void setest(string nest){         est.set(nest);     }  } 

i have verified estudiantes list in main class reading information csv, table still appears blank on gui. feedback , appreciated.

  • the line

    namecol.setcellvaluefactory(new propertyvaluefactory<tablaest,string>("nombre")); 

    says namecol table column should bind tablaest.nombreproperty(), or if doesn't exist, render tablaest.getnombre() field of tablaest instance cell value. since there no methods these, column empty.

  • you using simplestringproperty in tablaest class. in addition ordinary getters/setters, should add javafx specific getters like:

    private final simplestringproperty name; ... public string getname(){     return name.get(); }  public void setname(string nname){     name.set(nname); }  public stringproperty nameproperty(){     return name; } 

    for fields. if tableview going editable, new getter provide instant update underlying tablaest instance.
    can define

    namecol.setcellvaluefactory(new propertyvaluefactory<tablaest,string>("name")); 
  • the header names table columns should given setting text property:

    namecol.settext("the nombre"); 

    or in fxml

    <tablecolumn text="the nombre" .... > 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -