0

I am trying to put my test ObservableList data into JavaFX TableView i made with scene builder, but when i use setItems() i can see there are 5 rows of data, but cells in that row dont contain any data or at least i cant see it

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);
    }
}

and all i can see is:

this

i can select any row above selected, but cant go down with selection

  • [mcve] please .. and unrelated: please learn java naming conventions and stick to them – kleopatra Nov 06 '19 at 13:10
  • @kleopatra, sorry, i usually format code when it starts to work, but i should do this before posting so i edited question – Andrey Zotov Nov 06 '19 at 13:21
  • 1
    spelling of property is wrong in your PropertyValueFactory – kleopatra Nov 06 '19 at 13:30
  • @kleopatra can you please help me, why is it wrong? i copied it from tblQuery class and they have exact same names – Andrey Zotov Nov 06 '19 at 13:50
  • 1
    Instead of using PropertyValueFactory, which is based on reflection and cannot be checked for correctness by the compiler, consider writing your own short factory code. For an example, see https://stackoverflow.com/questions/58313782/javafx-tableview-row-added-but-not-visible/58322591#58322591. – VGR Nov 06 '19 at 15:38

1 Answers1

0

getID() is misspelled. It is suppose to be getId() in order to follow the bean convention. Here is modified working example.

    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);
        }
    }