将对象添加到observableList后,TableView不显示任何内容

时间:2018-01-27 08:24:47

标签: java javafx

我尝试向我创建的tableview添加行但是tableView在成功创建对象时保持为空(我打印出对象并看到数据是否正确)如何解决这个问题?

public class FirstFinalRep {

private final String fN;
private final Double bE;
private final Double aE;
private final Double dE;
private final Double bV;
private final Double aV;
private final Double dV;


public FirstFinalRep(String fN, double bE, double aE, double dE,
                     double bV, double aV, double dV) {
    this.fileName = fN;
    this.bEntropy = bE;
    this.aEntropy = aE;
    this.dEntropy = dE;
    this.bVol = bV;
    this.aVol = aV;
    this.dVol = dV;
}

我的控制器类是:

public class Controller {

@FXML
private TableView<FirstFinalRep> fFinalRepTable;
@FXML
private TableColumn<FirstFinalRep, String> fNameCol;
@FXML
private TableColumn<FirstFinalRep, Double> eBefCol;
@FXML
private TableColumn<FirstFinalRep, Double> eAfCol;
@FXML
private TableColumn<FirstFinalRep, Double> eDiCol;
@FXML
private TableColumn<FirstFinalRep, Double> vBefCol;
@FXML
private TableColumn<FirstFinalRep, Double> vAfCol;
@FXML
private TableColumn<FirstFinalRep, Double> vDifCol;

private List<FirstFinalRep> listFirstFinalLog= new ArrayList();
public static ObservableList<FirstFinalRep> observableFinalLogs;

public void initialize() {
    fNameCol.setCellValueFactory(new PropertyValueFactory<FirstFinalRep, String>("fName"));
    eBefCol.setCellValueFactory(new PropertyValueFactory<FirstFinalRep, Double>("bE"));
    eAfCol.setCellValueFactory(new PropertyValueFactory<FirstFinalRep, Double>("aE"));
    eDiCol.setCellValueFactory(new PropertyValueFactory<FirstFinalRep, Double>("dE"));
    vBefCol.setCellValueFactory(new PropertyValueFactory<FirstFinalRep, Double>("bV"));
    vAfCol.setCellValueFactory(new PropertyValueFactory<FirstFinalRep, Double>("aV"));
    vDifCol.setCellValueFactory(new PropertyValueFactory<FirstFinalRep, Double>("dV"));

    observableFinalLogs = FXCollections.observableArrayList(this.listFirstFinalLog);
    fFinalRepTable.setItems(this.observableFinalLogs);
}


public void startAnalysis() throws Exception {

    FirstFinalRep firstFinalRep = new FirstFinalRep("TA",1,2,3,4,5,6);
    observableFinalLogs.add(firstFinalRep);
}

如您所见,当我想将FirstFinalRep类的对象添加到可观察列表时,tableview(fFinalRepTable)没有任何要显示的东西(它是空的),它就像下面的图像: enter image description here

0 个答案:

没有答案