0

So I'm trying to get some TableViews to work and I've managed to get some of them working but some of my columns' data is missing and I don't quite get what's the difference that make some of the columns show up and others not. Here's the code for the initialisation of the tables:

void initTables(TableView<Layer> layerTable, TableView<Section> sectionTable, TableView<Edge> edgeTable){

    // Columnas de tabla ejes
    TableColumn<Edge, Integer> indexEdgeCol = new TableColumn<>("Numero"); //Not showing up
    indexEdgeCol.setMaxWidth(80.);
    indexEdgeCol.setCellValueFactory(new PropertyValueFactory<Edge, Integer>("Id"));
    TableColumn<Edge, Double> sepEdgeCol = new TableColumn<>("Separación"); //Not showing up
    sepEdgeCol.setMinWidth(110.);
    sepEdgeCol.setCellValueFactory(new PropertyValueFactory<Edge, Double>("Separación"));
    TableColumn<Edge, Double> loadEdgeCol = new TableColumn<>("Carga");
    loadEdgeCol.setMinWidth(110.);
    loadEdgeCol.setCellValueFactory(new PropertyValueFactory<Edge, Double>("Carga"));

    edgeTable.setItems(getData().getEdges());

    // Columnas de tabla tramos
    TableColumn<Section, Integer> indexSectionCol = new TableColumn<>("Número");
    indexSectionCol.setMaxWidth(100.);
    indexSectionCol.setCellValueFactory(new PropertyValueFactory<Section, Integer>("Id"));
    TableColumn<Section, Double> lengthSectionCol = new TableColumn<>("Longitud"); //Not showing up
    lengthSectionCol.setMinWidth(120.);
    lengthSectionCol.setCellValueFactory(new PropertyValueFactory<Section, Double>("Longitud"));
    TableColumn<Section, Integer> slabSectionCol = new TableColumn<>("Num. Losas"); //Not showing up
    slabSectionCol.setMinWidth(125.);
    slabSectionCol.setCellValueFactory(new PropertyValueFactory<Section, Integer>("losas"));

    sectionTable.setItems(getData().getSections());

    // Columnas de tabla capas
    TableColumn<Layer, Integer>indexLayerCol = new TableColumn<>("ID");
    indexLayerCol.setMaxWidth(40.);
    indexLayerCol.setCellValueFactory(new PropertyValueFactory<Layer, Integer>("Id"));
    TableColumn<Layer, String>nameLayerCol = new TableColumn<>("Nombre");
    nameLayerCol.setMinWidth(130.);
    nameLayerCol.setCellValueFactory(new PropertyValueFactory<Layer, String>("Name"));
    TableColumn<Layer, Double> modYoungLayerCol = new TableColumn<>("Mod. de Young");
    modYoungLayerCol.setMinWidth(101.);
    modYoungLayerCol.setCellValueFactory(new PropertyValueFactory<Layer, Double>("Young"));
    TableColumn<Layer, Double> thickLayerCol = new TableColumn<>("Espesor");
    thickLayerCol.setMinWidth(101.);
    thickLayerCol.setCellValueFactory(new PropertyValueFactory<Layer, Double>("Espesor"));

    layerTable.setItems(getData().getLayers());

    edgeTable.getColumns().setAll(indexEdgeCol, sepEdgeCol, loadEdgeCol);
    sectionTable.getColumns().setAll(indexSectionCol, lengthSectionCol, slabSectionCol);
    layerTable.getColumns().setAll(indexLayerCol, nameLayerCol, modYoungLayerCol, thickLayerCol);
}

As far as I know, data is as it should be, it's only that it's not getting shown in said tables and I don't quite know what I'm doing wrong, so any help would be appreciated. Thanks in advance!

EDIT: As requested, here are my Section and Edge classes:

Section.java:

import java.util.ArrayList;

public class Section extends Object{

    private final int id;
    private int bloques; 
    private double length;

    public Section(int id, int bloques, double length) {
        super();
        this.id = id;
        this.bloques = bloques;
        this.length = length;
        // this.start = start;
        // end = length + start;
    }

    public int getId(){
        return id;
    }

    public int getBloques(){
        return bloques;
    }

    public void setBloques(int bloques){
        this.bloques = bloques;
    }

    public double getLength() {
            return length;
    }

    public void setLength(double longitud) {
            this.length = longitud;
    }

    @Override
    public String toString() {
        return "Section [id=" + id  + ", length=" + length + ", bloques=" + bloques + "]";
    }
}

Edge.java:

public class Edge extends Object{

    private final int index;
    private double sep;
    private double carga;

    public Edge(int index, double sep, double carga){
        this.index = index;
        this.sep = sep;
        this.carga = carga;
    }

    public int getIndex(){
        return index;
    }

    public void setSep(double s){
        sep = s;
    }

    public double getSep(){
        return sep;
    }

    public void setCarga(double c){
        carga = c;
    }

    public double getCarga(){
        return carga;
    }

    @Override
    public String toString() {
        return "Edge [index=" + index + ", separación=" + sep + ", carga=" + carga + "]";
    }
}
A. Gimeno
  • 47
  • 8
  • Post your `Section` and `Edge` classes. – James_D Jan 11 '18 at 15:12
  • There you go mate. – A. Gimeno Jan 11 '18 at 15:21
  • the property name is "carga" (f.i.) that is, starts with a lower-case letter - @James_D this certainly is a duplicate but I'm too lazy to search ;) – kleopatra Jan 11 '18 at 15:32
  • Favor lambda expressions over `PropertyValueFactory` for the cell value factories (e.g. `indexEdgeCol.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getId()).asObject());`). This allows the compiler to check you are mapping to things that actually exist. If your model classes use [JavaFX Properties](http://www.oracle.com/pls/topic/lookup?ctx=javase80&id=JFXBD107), then the code is much cleaner (and you support editing in the table, if needed). – James_D Jan 11 '18 at 15:46

0 Answers0