不能在setItems()之后在tableview的单元格中看到数据

我正在尝试将我的测试ObservableList数据放入用场景构建器制作的JavaFX TableView中,但是当我使用setItems()时,我可以看到有5行数据,但是该行中的单元格不包含任何数据或至少我看不到

private final ObservableList<tblQuery> data =
        FXCollections.observableArrayList(
                new tblQuery("Jacob","Smith","jacob.smith@example.com"),//4 more rows
        );
private javafx.scene.control.TableView<tblQuery> tableview;

@Override
public void start(Stage primaryStage) throws Exception {
    FXMLLoader loader = new FXMLLoader(getclass().getResource("sample.fxml"));
    Parent root = loader.load();
    tableview = (TableView) loader.getNamespace().get("tabQuery");
    primaryStage.setTitle("Cycle reloader");
    primaryStage.setResizable(false);
    primaryStage.setScene(new Scene(root));

    tableview.setEditable(true);

    TableColumn coID = new TableColumn("Cycle№");
    coID.setMinWidth(80);
    coID.setCellValueFactory(
            new PropertyValueFactory<tblQuery,String>("id"));

    //workflow and date columns,same as id column

    tableview.setItems(data);
    tableview.getcolumns().addAll(coID,colWorkflow,colDate);

    primaryStage.show();

}

public class tblQuery {
    private final SimpleStringProperty id;
    private final SimpleStringProperty workflow;
    private final SimpleStringProperty date;

    private tblQuery(String id,String workflow,String date) {
        this.id = new SimpleStringProperty(id);
        this.workflow = new SimpleStringProperty(workflow);
        this.date = new SimpleStringProperty(date);
    }

    public String getID() {
        return id.get();
    }

    public void setID(String fName) {
        id.set(fName);
    }

    public String getWorkflow() {
        return workflow.get();
    }

    public void setWorkflow(String fName) {
        workflow.set(fName);
    }

    public String getDate() {
        return date.get();
    }

    public void setDate(String fName) {
        date.set(fName);
    }
}

我所能看到的是:

不能在setItems()之后在tableview的单元格中看到数据

我可以选择所选内容上方的任何行,但不能随选择项下移

lina111000 回答:不能在setItems()之后在tableview的单元格中看到数据

getID()拼写错误。为了遵循Bean约定,假设为getId()。 这是修改后的工作示例。

    import javafx.application.Application;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.scene.Scene;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.stage.Stage;

    public class TableApp extends Application {

        private final ObservableList<TblQuery> data =
                FXCollections.observableArrayList(
                        new TblQuery("Jacob","Smith","jacob.smith@example.com"),new TblQuery("Isabella","Johnson","isabella.johnson@example.com"),new TblQuery("Ethan","Williams","ethan.williams@example.com"),new TblQuery("Emma","Jones","emma.jones@example.com"),new TblQuery("Michael","Brown","michael.brown@example.com")
                );

        private javafx.scene.control.TableView<TblQuery> tableview = new TableView<>();

        public static void main(String[] args) {
            launch(args);
        }

        @Override
        public void start(Stage primaryStage) throws Exception {
            primaryStage.setTitle("Cycle reloader");
            primaryStage.setResizable(false);
            primaryStage.setScene(new Scene(tableview));

            tableview.setEditable(true);

            TableColumn idCol = new TableColumn("What");
            idCol.setMinWidth(80);
            idCol.setCellValueFactory(
                    new PropertyValueFactory<TblQuery,String>("id"));

            TableColumn workflowCol = new TableColumn("Workflow name");
            workflowCol.setMinWidth(236);
            workflowCol.setCellValueFactory(
                    new PropertyValueFactory<TblQuery,String>("workflow"));

            TableColumn dateCol = new TableColumn("AS OF DAY");
            dateCol.setMinWidth(80);
            dateCol.setCellValueFactory(
                    new PropertyValueFactory<TblQuery,String>("date"));

            tableview.setItems(data);
            tableview.getColumns().addAll(idCol,workflowCol,dateCol);

            primaryStage.show();
        }
    }
    import javafx.beans.property.SimpleStringProperty;

    public class TblQuery {

        private final SimpleStringProperty idProperty = new SimpleStringProperty();
        private final SimpleStringProperty workflowProperty = new SimpleStringProperty();
        private final SimpleStringProperty dateProperty = new SimpleStringProperty();

        public TblQuery(String id,String workflow,String date) {
            this.idProperty.set(id);
            this.workflowProperty.set(workflow);
            this.dateProperty.set(date);
        }

        public void setId(String id) {
            this.idProperty.set(id);
        }

        public String getId() {
            return idProperty.get();
        }

        public String getWorkflow() {
            return workflowProperty.get();
        }

        public void setWorkflow(String workflow) {
            this.workflowProperty.set(workflow);
        }

        public String getDate() {
            return dateProperty.get();
        }

        public void setDate(String date) {
            this.dateProperty.set(date);
        }
    }
本文链接:https://www.f2er.com/3151959.html

大家都在问