繁体   English   中英

从javafx中的多文本字段检索数据

[英]retrieve data from multi text field in javafx

我正在开发一个应用程序,在该应用程序中,用户应确定在用户确定文本字段数之后,应从在javaFX控制器中动态创建的文本字段中检索数据。 因为在第一个视图中我只有一个文本字段,所以我确实很容易地检索了它,没有问题,但是当从控制器动态创建文本字段时,我只是不知道如何进行操作。

我试图使用textfield.getText(); 但它不起作用。

这是我的代码:

public void handleButtonActionNext(ActionEvent event) throws IOException{

        String t = textField.getText();
        IntegerStringConverter a = new IntegerStringConverter();
        this.i = a.fromString(t);

        Node node = (Node) event.getSource();
        Stage stage = (Stage) node.getScene().getWindow();
        Scene scene = stage.getScene();
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ProcessusTimeExec.fxml"));
        Parent root = (Parent) fxmlLoader.load();
        scene.setRoot(root); 

        gridPane = (GridPane) FXMLLoader.load(getClass().getResource("ProcessusTimeExec.fxml"));
        Scene secondScene = new Scene(gridPane);
        gridPane.setPadding(new Insets(10, 10, 10, 10));

        this.listTextField = new ArrayList<>();

        for(int n=1; n<=i;n++){
                this.label = new Label("execution Time "+n);

                GridPane.setConstraints(label, 0, n+2);
                GridPane.setConstraints(textField, 1, n+2);
                gridPane.getChildren().add(textField);
                gridPane.getChildren().add(label);
            }

            stage.setScene(secondScene);
    }

在此Handlevent中,在同一控制器中,我试图检索数据以便将其发送到项目的逻辑部分。

public void handleButtonActionAlgo(ActionEvent event) throws IOException{

        Node node = (Node) event.getSource();
        Stage stage = (Stage) node.getScene().getWindow();
        Scene scene = stage.getScene();
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Algo.fxml"));

        Parent root = (Parent) fxmlLoader.load();
        scene.setRoot(root);

        // retrieve the data from the textFields      
    }

执行这些操作的按钮在FXML文件中。

就像是 :

       TextField textField[] = new TextField[...]; 

      for(int n=1; n<=i;n++) {
            textField[n] = new TextField("input "+n);
            gridPane.getChildren().add(textField[n]);
        }

您可以使用.getText()打印它们进行测试

    for(int n=1; n<=i;n++) {System.out.println(textField[n].getText());}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM