JavaFX | TableView不填充某些字段

时间:2019-05-19 13:08:47

标签: javafx tableview

我有一个TableView以及我的数据类中的获取器和设置器。除一个字段外,所有字段均已填充。我已经查看了我的代码,但不知道为什么。有人可以帮我吗?

我有一条条件语句说,如果找不到数据,请在表上显示N / A。该表在所有行上均显示N / A,但是如果我在控制台上输出此字段的值,则表明存在某些内容。

//populating my tableview...
    @Override
    public void initialize(URL location, ResourceBundle resources) {
      ConcreteObservable concreteObservable = new ConcreteObservable();   patientsTable.setItems(FXCollections.observableArrayList(concreteObservable.getPatients()));
        for (int i = 0; i < ConcreteObservable.PATIENTSLIST.size(); i++) {
            /*fields that are successfully populated are here, I removed them for space but I used the same 
format in the cholesterolCol, just changed columnName and data field name and it still wont work */
            cholesterolCol.setCellValueFactory(new PropertyValueFactory<>("currentCholesterolLevel"));
            dateRecordedCol.setCellValueFactory(new PropertyValueFactory<>("dateRecorded"));
        }
    }

这是我的数据类

public class ConcreteObservable implements IObservable {
      private String currentCholesterolLevel;

//method that sets the values of my data
public List<ConcreteObservable> getPatients(){
if (observation.getCode().getText().equals("Total Cholesterol")) {
  currentCholesterolLevel = observation.getValueQuantity().getValue().toString();
  setCurrentCholesterolLevel(currentCholesterolLevel);

//tried to do it this way incase the line above did not work
myPatient.setCurrentCholesterolLevel(currentCholesterolLevel);
         myPatient.setDateRecorded(dateRecorded);
        } else {
                 myPatient.setCurrentCholesterolLevel("N/A");
                 myPatient.setDateRecorded("No Cholesterol Recording");
                    }
return PATIENTSLIST;

                }

    public void setCurrentCholesterolLevel(String currentCholesterolLevel) {
             this.currentCholesterolLevel = currentCholesterolLevel;
         }

    public String getCurrentCholesterolLevel() {
                    return currentCholesterolLevel;
                }
}

我的表格视图仅填充N / A。我尝试过JOPtionPane.showMessageDialog(),但它确实向我显示了胆固醇的实际值,所以为什么不能设置它们,以便可以从表中读取它们(如果存在)?

0 个答案:

没有答案