0

This is a program for complaint management system. I am facing an issue that is I am not able to populate the tableview. When I click on refresh menuitem for refreshing(code is below you can check) it shows nothing but functions like some data is inserted there. Before Clicking Refresh After Clicking Refresh

            package sample;

            import javafx.collections.FXCollections;
            import javafx.collections.ObservableList;
            import javafx.scene.control.*;
            import javafx.scene.control.cell.PropertyValueFactory;
            import java.util.ArrayList;
            import java.util.Optional;

            /**
             * Created by Harshit on 12-04-2017.
             */
            public class vstaffcontroller{
                dbcon db = new dbcon();
                public MenuBar menubar;
                public Menu File,Help,Edit;
                public MenuItem logoutmenu,aboutmenu,refresh;
                public ObservableList<Person> list = FXCollections.observableArrayList();
                public TableView<Person> table = new TableView<Person>();
                public TableColumn compcol1;
                public TableColumn compcol2;
                public void logout(){
                    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
                    alert.setHeaderText("Are you sure you want to continue");
                    Optional<ButtonType> result = alert.showAndWait();
                    if(result.get()==ButtonType.OK){
                        System.exit(0);
                    }
                    else{
                        alert.close();
                    }
                }
                public void about(){
                    Alert alert = new Alert(Alert.AlertType.INFORMATION);
                    alert.setTitle("About the Software");
                    alert.setContentText("This window is for Verification Staff. \n Click Refresh for refreshing the complaints \n Other verification and other options are in Edit Menu");
                    alert.setHeaderText("IP of Antilia Technologies - Harshit Pareek");
                    alert.showAndWait();
                }
                public void refresh(){
                    compcol1.setCellValueFactory(
                            new PropertyValueFactory<Person,String>("complaint_no")
                    );
                    compcol2.setCellValueFactory(
                            new PropertyValueFactory<Person,String>("details")
                    );
                    String statement = "SELECT complaint_no,details FROM complaints";
                    db.getcompData(statement,list);
                    System.out.print(list);
                    table.setItems(list);
                }
            }

This file is for linking the application to the FXML file.

        package sample;

        import javafx.application.Application;
        import javafx.fxml.FXMLLoader;
        import javafx.scene.Parent;
        import javafx.scene.Scene;
        import javafx.stage.Stage;

        /**
         * Created by Harshit on 12-04-2017.
         */
        public class vstaffmpage extends Application {
            @Override
            public void start(Stage primaryStage) throws Exception {
                Parent root = FXMLLoader.load(getClass().getResource("vstaff.fxml"));
                primaryStage.setTitle("Verification Staff");
                primaryStage.setScene(new Scene(root, 600, 400));
                primaryStage.setResizable(false);
                primaryStage.show();
            }
            public static void main(String[] args){ launch(args); }
            vstaffmpage(){
                Stage stage = new Stage();
                try {
                    start(stage);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

This file is for putting data in the string and than taking it into the observablelist. I have created this file as per given on the oracle website.

    package sample;

    import javafx.beans.property.SimpleStringProperty;

    public class Person {
       private final SimpleStringProperty complaint_no;
       private final SimpleStringProperty details;
    public Person() {
            this("", "");
        }

        public Person(String complaint_no, String details) {
            this.complaint_no = new SimpleStringProperty("complaint_no");
            this.details = new SimpleStringProperty("details");
        }

        public String getcomplaintno() {
            return complaint_no.get();
        }

        public void setcomplaintno(String complaintno) {
            complaint_no.set(complaintno);
        }

        public String getdetails() {
            return details.get();
        }

        public void setdetails(String detail) {
            details.set(detail);
        }

    }

Below is the FXML file for the program.

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #9f9de8;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.vstaffcontroller">
   <children>
      <TableView fx:id="table" editable="true" layoutX="153.0" layoutY="64.0" prefHeight="316.0" prefWidth="433.0">
        <columns>
          <TableColumn fx:id="compcol1" prefWidth="127.0" resizable="false" text="Complaint Number" />
          <TableColumn fx:id="compcol2" minWidth="0.0" prefWidth="305.0" text="Details" />
        </columns>
      </TableView>
      <MenuBar fx:id="menubar" prefHeight="25.0" prefWidth="600.0">
        <menus>
          <Menu fx:id="File" mnemonicParsing="false" text="File">
            <items>
              <MenuItem fx:id="logoutmenu" mnemonicParsing="false" onAction="#logout" text="Logout" />
            </items>
          </Menu>
          <Menu fx:id="Edit" mnemonicParsing="false" text="Edit">
            <items>
              <MenuItem fx:id="refresh" mnemonicParsing="false" onAction="#refresh" text="Refresh" />
                  <MenuItem mnemonicParsing="false" text="Verify" />
                  <MenuItem mnemonicParsing="false" text="Bogus Complaint" />
            </items>
          </Menu>
          <Menu fx:id="Help" mnemonicParsing="false" text="Help">
            <items>
              <MenuItem fx:id="aboutmenu" mnemonicParsing="false" onAction="#about" text="About" />
            </items>
          </Menu>
        </menus>
      </MenuBar>
   </children>
</AnchorPane>
Hpareek07
  • 21
  • 2
  • From what I can see you are not actually linking your controls to your FXML. You need the @FXML annotation to link the FXML to your controller. – purring pigeon Apr 14 '17 at 19:22
  • @purringpigeon You don't need `@FXML` if the fields are public (which, obviously, they should not be, but this code will "work"). – James_D Apr 15 '17 at 00:50

0 Answers0