1

I'm Actually new with JavaFX and been facing an issue to view the data on the table. What I'm trying to do is to create a new stage on a Mouse Click Event of an Imageview where the Fields will be provided to the user to enter the data to the table on the parent node.

This is the function which is called on the mouse click event that creates a child node(stage) :

private void addQualification(MouseEvent event) {

    System.out.println("Add Qualification Method");
    final Stage dialog = new Stage();
    dialog.setTitle("Add a Qualification");
    dialog.initModality(Modality.WINDOW_MODAL);
    dialog.initStyle(StageStyle.UTILITY);

    // create a grid for the data entry.
    GridPane grid = new GridPane();

    AnchorPane anchorPane = new AnchorPane(grid);

    ObservableList<String> QualChoiceList = FXCollections.observableArrayList("MBBS/MSC ", "MD/MS/DNB/PhD", "DM/M Ch.");
    final ChoiceBox<String> QualChoice = new ChoiceBox<String>();
    QualChoice.setValue("Select a Qualification");
    QualChoice.setItems(QualChoiceList);
    final TextField College = new TextField();
    final TextField University = new TextField();
    final TextField PassingYear = new TextField();
    final TextField RegNo = new TextField();
    final TextField StateName = new TextField();
    grid.addRow(0, new Label("Qualification"), QualChoice);
    grid.addRow(1, new Label("College"), College);
    grid.addRow(2, new Label("University"), University);
    grid.addRow(3, new Label("Year of Passing"), PassingYear);
    grid.addRow(4, new Label("Registration No."), RegNo);
    grid.addRow(5, new Label("Name of State"), StateName);
    grid.setHgap(10);
    grid.setVgap(10);
    GridPane.setHgrow(QualChoice, Priority.ALWAYS);
    GridPane.setHgrow(College, Priority.ALWAYS);
    GridPane.setHgrow(University, Priority.ALWAYS);
    GridPane.setHgrow(PassingYear, Priority.ALWAYS);
    GridPane.setHgrow(RegNo, Priority.ALWAYS);
    GridPane.setHgrow(StateName, Priority.ALWAYS);

    // create action buttons for the dialog.
    Button ok = new Button("Add");
    Button cancel = new Button("Cancel");
    ok.setDefaultButton(true);
    cancel.setCancelButton(true);

    anchorPane.getChildren().add(ok);
    anchorPane.getChildren().add(cancel);

    AnchorPane.setTopAnchor(grid, 20.0);
    AnchorPane.setLeftAnchor(grid, 20.0);
    AnchorPane.setRightAnchor(grid, 20.0);
    AnchorPane.setBottomAnchor(grid, 80.0);

    AnchorPane.setTopAnchor(ok, 240.0);
    AnchorPane.setLeftAnchor(ok, 100.0);
    AnchorPane.setRightAnchor(ok, 214.0);
    AnchorPane.setBottomAnchor(ok, 30.0);

    AnchorPane.setTopAnchor(cancel, 240.0);
    AnchorPane.setLeftAnchor(cancel, 230.0);
    AnchorPane.setRightAnchor(cancel, 95.0);
    AnchorPane.setBottomAnchor(cancel, 30.0);

    dialog.setScene(new Scene(anchorPane, 400, 310));

    dialog.show();
    // only enable the ok button when there has been some text entered.
    ok.disableProperty().bind(College.textProperty().isEqualTo("").or(University.textProperty().isEqualTo("")).or(PassingYear.textProperty().isEqualTo("")).or(RegNo.textProperty().isEqualTo("")).or(StateName.textProperty().isEqualTo("")));

    // add action handlers for the dialog buttons.
    ok.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            int nextIndex = QualTable.getSelectionModel().getSelectedIndex() + 1;
            QualTable.getItems().add(nextIndex, new Qualification(QualChoice.getValue(), College.getText(), University.getText(), PassingYear.getText(), RegNo.getText(), StateName.getText()));
            QualTable.getSelectionModel().select(nextIndex);
            dialog.close();
        }
    });
    cancel.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            dialog.close();
        }
    });

This is the Qualification Class that I have used to inout the values to the QualTable using the add Method:

public static class Qualification {

    private StringProperty Qual;
    private StringProperty College;
    private StringProperty University;
    private StringProperty PassingYear;
    private StringProperty RegNo;
    private StringProperty StateName;

    public Qualification(String Qual, String College, String University, String PassingYear, String RegNo, String StateName) {
        setQual(Qual);
        setCollege(College);
        setUniversity(University);
        setPassingYear(PassingYear);
        setRegNo(RegNo);
        setStateName(StateName);

    }

    public String getQual() {
        return QualProperty().get();
    }

    public String getCollege() {
        return CollegeProperty().get();
    }

    public String getUniversity() {
        return UniversityProperty().get();
    }

    public String getPassingYear() {
        return PassingYearProperty().get();
    }

    public String getRegNo() {
        return RegNoProperty().get();
    }

    public String getStateName() {
        return StateNameProperty().get();
    }

    public final void setQual(String value) {
        QualProperty().set(value);
    }

    public final void setCollege(String Coll) {
        CollegeProperty().set(Coll);
    }

    public final void setUniversity(String Univ) {
        UniversityProperty().set(Univ);
    }

    public final void setPassingYear(String PsngYr) {
        PassingYearProperty().set(PsngYr);
    }

    public final void setRegNo(String Reg) {
        RegNoProperty().set(Reg);
    }

    public final void setStateName(String StNm) {
        StateNameProperty().set(StNm);
    }

    public StringProperty QualProperty() {
        if (Qual == null) {
            Qual = new SimpleStringProperty(this, "Qual");
        }
        return Qual;
    }

    public StringProperty CollegeProperty() {
        if (College == null) {
            College = new SimpleStringProperty(this, "College");
        }
        return College;
    }

    public StringProperty UniversityProperty() {
        if (University == null) {
            University = new SimpleStringProperty(this, "University");
        }
        return University;
    }

    public StringProperty PassingYearProperty() {
        if (PassingYear == null) {
            PassingYear = new SimpleStringProperty(this, "PassingYear");
        }
        return PassingYear;
    }

    public StringProperty RegNoProperty() {
        if (RegNo == null) {
            RegNo = new SimpleStringProperty(this, "RegNo");
        }
        return RegNo;
    }

    public StringProperty StateNameProperty() {
        if (StateName == null) {
            StateName = new SimpleStringProperty(this, "StateName");
        }
        return StateName;
    }
}

This is the FXML code of the Anchor Pane consisting the tableview QualTable

I Need help on this tableview and the function that I'm using to populate the table view... The values are properly carried through the Qualification class but the tableview is not displaying the values on the row....

Please help me out through this and Thanks in Advance..!!!

  • 1
    1. [mcve] please 2. java naming conventions 3. see https://stackoverflow.com/questions/18971109/javafx-tableview-not-showing-data-in-all-columns – kleopatra Feb 15 '20 at 22:48

0 Answers0