在我的Java Fx应用程序中,我创建了两个阶段。第一阶段是主控制器类HomeController
中的默认阶段。第二个AddNewEmailController
是通过调用showNewComposeNewEmail()
类中的方法AddNewEmailController
创建的。
新阶段创建得很好,但我尝试调用的方法都没有,比如关闭AddNewEmailController
阶段,将在AddNewEmailController
阶段工作。
如何让方法起作用?
我也想在HomeController
阶段打开后无法访问AddNewEmailController
阶段,就像弹出窗口一样。
我甚至无法将AddNewEmailController
阶段变为 iconify ?
提前谢谢大家。
HomeController类:
public class HomeController implements Initializable {
// Initializes the controller class.
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
@FXML
public void windowClose() {
Platform.exit();
}
@FXML
public void showNewComposeNewEmail() throws Exception {
new AddNewEmailController().newnewcomposeNewEmailStage();
}
}
AddNewEmailController类:
public class AddNewEmailController implements Initializable {
public void setScreenParent(ScreensController screenParent) {
myController = screenParent;
}
// Initializes the controller class.
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
public Stage newComposeNewEmail;
public void newnewcomposeNewEmailStage() throws IOException {
newComposeNewEmail = new Stage();
newComposeNewEmail.initStyle(StageStyle.UNDECORATED);
newComposeNewEmail.initStyle(StageStyle.TRANSPARENT);
Parent newComposeNewEmailRoot = FXMLLoader.load(getClass().getResource("/wakiliproject/Forms/AddNew/NewEmail/NewEmail.fxml"));
StageDraggable.stageDraggable(newComposeNewEmailRoot, newComposeNewEmail);
Scene newComposeNewEmailScene = new Scene(newComposeNewEmailRoot, 590, 670);
newComposeNewEmail.setScene(newComposeNewEmailScene);
newComposeNewEmail.show();
}
@FXML
private void newComposeNewEmailClose() {
newComposeNewEmail.close();
}
@FXML
private void newComposeNewEmailIconify() {
newComposeNewEmail.setIconified(true);
}
}
的更新: 的
NewEmail FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="wakiliproject.Forms.AddNew.NewEmail.TryEMailController">
<children>
<Label layoutX="190.0" layoutY="61.0" onMouseClicked="#newComposeNewEmailStageIconify" text="Minimise Window" />
<Label layoutX="300.0" layoutY="61.0" onMouseClicked="#newComposeNewEmailStageClose" text="Close Window" />
</children>
</AnchorPane>
答案 0 :(得分:1)
在您的fxml中,您的controller
是
fx:controller="wakiliproject.Forms.AddNew.NewEmail.TryEMailController"
在您的代码中,类名是
AddNewEmailController
请使它们相同并重新检查,您的方法将被调用。
为了使新舞台成为家长的孩子,请使用
newStage.initModality(Modality.WINDOW_MODAL);
newStage.initOwner(PrimaryStage);