JavaFX Changeing Stage / Scene在之前的窗口中没有重置值

时间:2018-12-19 11:08:08

标签: javafx

我有一个可以发送电子邮件的应用程序或屏幕。我还有一个模板屏幕,它是一个全新的窗口。例如我已经在TO TextField中写了3个电子邮件地址。我希望他们留下来,即使我改变整个阶段,因为当我转到TemplatePicker屏幕并选择一个模板时,初始化将在EmailController中再次被调用,而TextField中的所有收件人都消失了。

代码电子邮件:

public void buttonPickTemplate(ActionEvent event) throws IOException {
    Main.fxmlval.add("/application/controller/MailController/SendMail.fxml");
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/application/controller/TemplateController/TemplateAuswahlFenster.fxml"));
    Parent parent = loader.load();
    TemplateController templateController = loader.<TemplateController>getController();
    templateController.setEmailVariablen(empfaengerField.getText(), ccField.getText(), bccField.getText(), betreffField.getText());
    Scene homeScreenScene = new Scene(parent);
    Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
    window.setScene(homeScreenScene);
}

如您所见,我试图将带有setter的变量提供给下一个屏幕,然后将它们重新设置,但这太可怕了。通常,如果您不必抛出任何变量,则更改屏幕的方法始终如下所示:

Parent detailsScreen = FXMLLoader.load(getClass().getResource("/application/controller/DetailsController/Details.fxml"));
Scene detailsScene = new Scene(detailsScreen);

Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(detailsScene);

因此,TemplateController中的此方法再次调用EmailController和FXML:

public void auswaehlen(ActionEvent event)throws IOException
{
    FXMLLoader loader = new FXMLLoader(getClass().getResource("../MailController/SendMail.fxml"));
    Parent homeScreen = loader.load();
    MailSender wpc=loader.<MailSender>getController();
    wpc.setTemplate(this.settemplate.getDatei());
    Scene homeScreenScene = new Scene(homeScreen);

    Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();

    window.setScene(homeScreenScene);
}

This is the email Screen which gets cleared when loading a template

0 个答案:

没有答案