javaFX Tableview Data not visible


Question

I tried all to populate a TableView with data. The next code inserts a new row in table but the data not appear the table. I tried to find an explication for this without success.

Please help. I can't what is wrong.

In controller.java

@FXML private TableView<TempTableData> tempTable;
@FXML private TableColumn<TempTableData,String> columnTime;
@FXML private TableColumn<TempTableData,Float> columnTempOne;
@FXML private TableColumn<TempTableData,Float> columnTempTwo;
@FXML private TableColumn<TempTableData,Float> columnTempThree;

@FXML protected void initialize() {


columnTime = new TableColumn<TempTableData,String>();
columnTime.setCellValueFactory(
    new PropertyValueFactory<TempTableData,String>("Time"));

columnTempOne = new TableColumn<TempTableData,Float>();
columnTempOne.setCellValueFactory(
    new PropertyValueFactory<TempTableData,Float>("Temp 1"));

columnTempTwo = new TableColumn<TempTableData,Float>();
columnTempTwo.setCellValueFactory(
    new PropertyValueFactory<TempTableData,Float>("Temp 2"));

columnTempThree = new TableColumn<TempTableData,Float>();
columnTempThree.setCellValueFactory(
    new PropertyValueFactory<TempTableData,Float>("Temp 3"));

tempDataList = FXCollections.observableArrayList();
tempDataList.add(new TempTableData("0",3.0f, 4f, 5f));
tempTable.setItems(tempDataList);
}

TempTableData.java

public class TempTableData {

private final SimpleStringProperty time;
private final SimpleFloatProperty dataSensorOne;
private final SimpleFloatProperty dataSensorTwo;
private final SimpleFloatProperty dataSensorThree;

public TempTableData(String time, float dataSensorOne, float dataSensorTwo, float dataSensorThree){
    this.time = new SimpleStringProperty(time);
    this.dataSensorOne = new SimpleFloatProperty(dataSensorOne);
    this.dataSensorTwo = new SimpleFloatProperty(dataSensorTwo);
    this.dataSensorThree = new SimpleFloatProperty(dataSensorThree);
}
public String getTime() {
    return time.get();
}

public void setTime(String time) {
    this.time.set(time);
}

public float getDataSensorOne() {
    return dataSensorOne.get();
}

public void setDataSensorOne(float dataSensorOne) {
    this.dataSensorOne.set(dataSensorOne);
}

public float getDataSensorTwo() {
    return dataSensorTwo.get();
}

public void setDataSensorTwo(float dataSensorTwo) {
    this.dataSensorTwo.set(dataSensorTwo);
}

public float getDataSensorThree() {
    return dataSensorThree.get();
}

public void setDataSensorThree(float dataSensorThree) {
    this.dataSensorThree.set(dataSensorThree);
}

public String toString(){
    String string = String.format("[time: %s | dataSensorOne: %f |dataSensorTwo: %f |dataSensorThree: %f ]", 
            time.get(), dataSensorOne.get(), dataSensorTwo.get(), dataSensorThree.get());
    return string;
}
}
1
2
1/10/2013 8:12:27 PM

why you creating table columns again ? ,as they already created with @FXML annotation (injection!).

remove column instance creation lines from your code and everything will be fine

// remove these lines
columnTime = new TableColumn<TempTableData,String>();
columnTempTwo = new TableColumn<TempTableData,Float>();
columnTempThree = new TableColumn<TempTableData,Float>();
4
1/10/2013 8:30:42 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon