JavaFX tableView未填充,可以';我看不出有错

JavaFX tableView未填充,可以';我看不出有错,javafx,Javafx,我不明白为什么我的TableView没有设置数据。看起来一切正常,但行就是不会出现。我浏览了教程,但仍然没有看到我的错误。这是我的代码。 数据类: package model.elastic; import javafx.beans.property.SimpleStringProperty; public class ElasticAttribute { private SimpleStringProperty name; private SimpleStringProperty typ

我不明白为什么我的TableView没有设置数据。看起来一切正常,但行就是不会出现。我浏览了教程,但仍然没有看到我的错误。这是我的代码。 数据类:

package model.elastic;

import javafx.beans.property.SimpleStringProperty;

public class ElasticAttribute {

private SimpleStringProperty name;
private SimpleStringProperty type;
private SimpleStringProperty variable;

public ElasticAttribute(String name, String type, String variable) {
    this.name = new SimpleStringProperty(name);
    this.type = new SimpleStringProperty(type);
    this.variable = new SimpleStringProperty(variable);
}

public String getName() {
    return name.get();
}

public void setName(String name) {
    this.name.set(name);
}

public String getType() {
    return type.get();
}

public void setType(String type) {
    this.type.set(type);
}

public String getVariable() {
    return variable.get();
}

public void setVariable(String variable) {
    this.variable.set(variable);
}

}
控制员:

@FXML
private TableView<ElasticAttribute> tableView;

private TableColumn tableColumnName;

private TableColumn tableColumnType;

private TableColumn tableColumnVariable;

public void initialize() {

    final ObservableList<ElasticAttribute> data = FXCollections.observableArrayList(
            new ElasticAttribute("Test", "Test", "Test"),
            new ElasticAttribute("Test2", "Test", "Test"),
            new ElasticAttribute("Test3", "Test", "Test"),
            new ElasticAttribute("Test4", "Test", "Test"),
            new ElasticAttribute("Test5", "Test", "Test")
    );

    tableColumnName = new TableColumn("Name");
    tableColumnName.setCellValueFactory(
            new PropertyValueFactory<ElasticAttribute, String>("name"));
    tableColumnType = new TableColumn("Type");
    tableColumnType.setCellValueFactory(
            new PropertyValueFactory<ElasticAttribute, String>("type"));
    tableColumnVariable = new TableColumn("Variable");
    tableColumnVariable.setCellValueFactory(
            new PropertyValueFactory<ElasticAttribute, String>("variable"));
    tableView.setItems(data);
    tableView.getColumns().addAll(tableColumnName, tableColumnType, tableColumnVariable);
@FXML
私有TableView TableView;
私有TableColumn tableColumnName;
私有表列表列类型;
私有TableColumn TableColumn变量;
公共无效初始化(){
最终ObservableList数据=FXCollections.observableArrayList(
新的弹性属性(“测试”、“测试”、“测试”),
新的弹性属性(“Test2”、“Test”、“Test”),
新的弹性属性(“Test3”、“Test”、“Test”),
新的弹性属性(“Test4”、“Test”、“Test”),
新的弹性属性(“Test5”、“Test”、“Test”)
);
tableColumnName=新的TableColumn(“名称”);
tableColumnName.setCellValueFactory(
新财产价值工厂(“名称”);
tableColumnType=新的TableColumn(“类型”);
tableColumnType.setCellValueFactory(
新财产价值工厂(“类型”);
tableColumnVariable=新的TableColumn(“变量”);
tableColumnVariable.setCellValueFactory(
新属性值工厂(“变量”);
tableView.setItems(数据);
tableView.getColumns().addAll(tableColumnName、tableColumnType、tableColumnVariable);
fxml:

<TableView fx:id="tableView" GridPane.rowIndex="1">
    <columnResizePolicy>
        <TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
    </columnResizePolicy>
</TableView>


谢谢您的帮助。

我看不出您共享的代码有任何问题,所以我猜问题出在其他地方。可能您正在重新创建TableView,因此您看到的不是您在
初始化
中访问的TableView?提供了代码的相关部分(提到
TableView
、您的FXML等)可能会有帮助。您访问的控制器中还有其他地方吗
tableView
?列标题出现了吗,还是也没有?没有其他地方…,列标题出现了哦,该死,实际上我访问了它:bindBidirective(tableView.itemsProperty(),element.listProperty());这使得元素不出现。我看不出您共享的代码有任何错误,所以我猜问题出在其他地方。也许您正在重新创建一个TableView,所以您看到的不是您在
初始化
?中访问的,它提供了代码的相关部分(提到
TableView
,您的FXML等等)可能会有帮助。您访问的控制器中还有其他地方吗
tableView
?列标题出现了吗,还是也没有?没有其他地方…,列标题出现了哦,该死,实际上我访问了它:bindBidirective(tableView.itemsProperty(),element.listProperty());这使得元素没有出现