Java:将值从一个文本字段传递到另一个

时间:2018-10-23 13:48:50

标签: java netbeans controller fxml scenebuilder

我有两个控制器。第一个称为bookController,第二个称为categoryController(该控制器通过单击bookController上存在的按钮出现在屏幕上)。我正在尝试将值从categoryController上的类别的文本字段传递到在bookController上称为category的另一个文本字段。当我单击categoryController上的保存按钮(btnsave)时,我希望这些值从一个文本字段传递到另一个文本字段。

这就是我试图做到的方式:

在categoryController上:

private void btnsave_action(ActionEvent event) {
    String Text;
    Text=categories.getText();
    System.out.print(Text); 

    FXMLLoader Loader = new FXMLLoader();
    Loader.setLocation(getClass().getResource("book.fxml"));
    try {
        Loader.load();
    }catch (IOException ex) {
        Logger.getLogger(categoryController.class.getName()).log(Level.SEVERE,null,ex);
    }
    bookController copytext=Loader.getController();
    copytext.setText(Text);
}

在bookController上:

public void setText(String Text ) {
    this.categories.setText(Text);
    System.out.print(Text);
}

0 个答案:

没有答案