无法在运行时在javafx文本上设置文本

时间:2017-05-15 09:40:38

标签: javafx textfield

请我尝试在文本字段上设置文本,因为它已经从登录窗口打开了,但是它没有显示的更改是新的java和javafx下面是打开新窗口的代码

try {
        Statement stmnt= conn.createStatement();
        rs=stmnt.executeQuery(sql);
        if(rs.next()==true){

            String name = null;
            Image img = null;


                 name = rs.getString("name");
                 img = new Image(rs.getBinaryStream("photo"));
                 System.out.println(name);


                Stage primaryStage = new Stage();

                /*FXMLLoader loader = new FXMLLoader();

                Pane root = loader.load(getClass().getResource("main.fxml").openStream());
                mainController mnctrl = (mainController) loader.getController();
                mnctrl.dispOpInfo(name, img);*/

                FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("main.fxml"));     

                Parent root = (Parent)fxmlLoader.load();          
                mainController controller = fxmlLoader.<mainController>getController();
                controller.dispOpInfo(name, img);

                primaryStage.show(); 

                Scene scene = new Scene(root);
                scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
                primaryStage.setScene(scene);
                primaryStage.setTitle("BECE 2017 Validation");;
                primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
                primaryStage.show();
                //

        }

及以下是新打开的窗口的代码,textfield在运行时不会改变

 @FXML TextField txtSchName = new TextField();

    public void populateCanInfo (String canSchool, String canName, String canState,String canGender, Image canPhoto){
            System.out.println(canGender );
            txtCanName.setText(canName);
            txtSchName.setText(canSchool);
            imgViewCan.setImage(canPhoto);

        //  int index=cmbCanState.getValue().indexOf(canState);
        //  cmbCanState.getSelectionModel().select(index);

            if(canGender.equalsIgnoreCase(canGender)){
                rbtMale.setSelected(true);
            }else{
                rbtFemale.setSelected(true);
            }

        }

0 个答案:

没有答案