Java TableView不只填充一列

时间:2018-11-16 11:49:13

标签: java

我似乎无法填充“表视图”列之一。问题所在的专栏是我的“ complianceReq”。奇怪的是,如果我将“ brandName”交换为“ complianceReq”,它将正确显示品牌名称信息。但是我似乎无法显示“ complianceReq”。我尝试同时使用布尔值和String版本,但均未成功。

我可以确认变量是否具有true / false或Yes / No(取决于我尝试的版本)。

我还可以看到没有同时调用Getter方法。

我正在使用的类的代码在这里:https://pastebin.com/gswutwk0

这是我的控制器类:

private DBReader dbr;

@FXML
public TableView<JobSummaryData> tblView;

@FXML
public void updateTable() {

    ObservableList<JobSummaryData> obLst = FXCollections.observableArrayList(dbr.getJobSummary());

    tblView.getColumns().clear();
    tblView.setItems(obLst);

    TableColumn<JobSummaryData,Integer> colJobItem = new TableColumn<JobSummaryData,Integer>("Job Item Id");
    colJobItem.setCellValueFactory(new PropertyValueFactory<JobSummaryData,Integer>("jobItemId"));

    TableColumn<JobSummaryData,String> colBrandName = new TableColumn<JobSummaryData,String>("Brand Name");
    colBrandName.setCellValueFactory(new PropertyValueFactory<JobSummaryData,String>("brandName"));

    TableColumn<JobSummaryData,String> colCompliance = new TableColumn<JobSummaryData,String>("Compliance Required");
    colCompliance.setCellValueFactory(new PropertyValueFactory<JobSummaryData,String>("complianceReq"));

    TableColumn<JobSummaryData,String> colLink = new TableColumn<JobSummaryData,String>("Survey Link");
    colLink.setCellValueFactory(new PropertyValueFactory<JobSummaryData,String>("surveyLink"));

    tblView.getColumns().addAll(colJobItem, colBrandName, colCompliance, colLink);
}

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
    dbr = new DBReader();
}

这是我的JobSummaryData类:

private int jobItemId, submittedMinutes;
private String brandName, storeId, storeName, storeLocation, jobType, status, merchandiserName, agentNumber, areaManagerName, uncompleteReason; //complianceReq
private String eMail, mobile, surveyLink; //TBA Pref contact method
private boolean complianceRequired;
private Date jobDate;

public JobSummaryData(ResultSet rs) throws SQLException {

    jobItemId = rs.getInt("jobitemid");
    submittedMinutes = rs.getInt("submittedminutes");

    brandName = rs.getString("brandname");

    storeId = rs.getString("storeid");
    storeName = rs.getString("storename");
    storeLocation = rs.getString("storelocation");
    jobType = rs.getString("jobtype");
    status = rs.getString("Status");
    merchandiserName = rs.getString("merchandisername");
    agentNumber = rs.getString("agentnumber");
    areaManagerName = rs.getString("areamanagername");
    uncompleteReason = rs.getString("uncompletereason");

    eMail = rs.getString("Email");
    mobile = rs.getString("Mobile");
    surveyLink = rs.getString("SurveyLink");        

    complianceRequired = rs.getBoolean("ComplianceRequired");
    /*if(rs.getBoolean("ComplianceRequired")) {
        complianceReq = "Yes";
    }
    else {
        complianceReq = "No";
    }*/

    jobDate = rs.getDate("jobdate");
}

public int getJobItemId() {return jobItemId;}
public int getSubmittedMins() {return submittedMinutes;}

public String getBrandName() {return brandName;}
public String getStoreId() {return storeId;}
public String getStoreName() {return storeName;}
public String getStoreLocation() {return storeLocation;}
public String getJobType() {return jobType;}
public String getJobStatus() {return status;}
public String getMerchName() {return merchandiserName;}
public String getAgentNum() {return agentNumber;}
public String getAreaManagerNum() {return areaManagerName;}
public String getUncompReason() {return uncompleteReason;}

public String getEMail() {return eMail;}
public String getMobile() {return mobile;}
public String getSurveyLink() {return surveyLink;}

//public String getComplianceRequired() {return complianceReq;}
public boolean getComplianceBool() {return complianceRequired;}

public Date getJobDate() {return jobDate;}

我错过了什么? 谢谢

1 个答案:

答案 0 :(得分:0)

您将"complianceReq"传递给PropertyValueFactory,但是您的getComplianceReq()类中没有JobSummaryData方法。 PropertyValueFactory类要求getter和setter遵循Java Bean命名约定。

将单元格值工厂更改为:

colCompliance.setCellValueFactory(new PropertyValueFactory<>("complianceRequired"));

JobSummaryData类中的吸气剂更改为:

public String getComplianceReq() { return complianceReq; }

如果您曾经为JobSummaryData类实现JavaFX属性,请不要忘记添加正确命名的属性获取器-complianceRequiredProperty()complianceReqProperty(),具体取决于。