尊敬的开发人员,我有更多的阶段,但是当我打开任何阶段时,如下面的图片所示,因此,亲爱的开发人员,我需要在一个窗口中了解如何编写代码吗?
此代码例如开放舞台
@FXML
public void btnsaveinvoice() throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/FX/saveinvoice.fxml"));
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(scene);
stage.setTitle("saveInvoice");
stage.getIcons().add(new Image(getClass().getResourceAsStream("/image/restlogo.png")));
stage.show();
}
这是用于销售发票公开阶段的
@FXML
public void opensalesinvoice() {
try {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("/FX/salesinterface.fxml"));
Scene scene = new Scene(fxmlLoader.load());
Stage stage = new Stage();
stage.getIcons().add(new Image(getClass().getResourceAsStream("/image/restlogo.png")));
stage.setTitle("SalesInvoice");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
Logger logger = Logger.getLogger(getClass().getName());
logger.log(Level.SEVERE, "Failed to create new Window.", e);
}
}
答案 0 :(得分:-1)
您需要像这样将子阶段设置为父阶段
childStage.initOwner(parentStage);
EX。
@FXML
public void btnsaveinvoice() throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/FX/saveinvoice.fxml"));
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(scene);
stage.setTitle("saveInvoice");
stage.iniOwner(primaryStage); // or whatever your primaryStage is
stage.getIcons().add(new Image(getClass().getResourceAsStream("/image/restlogo.png")));
stage.show();
}