简体   繁体   English

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

[英]retrieve data from multi text field in javafx

i'm working on an application where i should retrieve data from text fields that i created dynamically in a javaFX controller after that the user decides the number of the text fields. 我正在开发一个应用程序,在该应用程序中,用户应确定在用户确定文本字段数之后,应从在javaFX控制器中动态创建的文本字段中检索数据。 since in the first view i have only one textfield, i did retrieve it easily with no problem but i just have no clue about how to do it when the text field are dynamically created from the controller. 因为在第一个视图中我只有一个文本字段,所以我确实很容易地检索了它,没有问题,但是当从控制器动态创建文本字段时,我只是不知道如何进行操作。

i tried to use the textfield.getText(); 我试图使用textfield.getText(); but it's not working. 但它不起作用。

this is my code: 这是我的代码:

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

here in this Handlevent in the same controller i'm trying to retrieve the data in order to send it to the logic part of my project. 在此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      
    }

the button that takes those actions is in the FXML file. 执行这些操作的按钮在FXML文件中。

Something like : 就像是 :

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

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

You can test by printing them using .getText() 您可以使用.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