I have a Swing application integrated with JavaFX. Swing JFrame is a top-level window in which the JFXPanel contains various JavaFX controls. Now I am also integrating the new JavaFX Alert API and am currently having difficulty setting permissions to Alert when displayed. That is, I would like to make JFrame the owner of Alert.
JFXPanel fxPanel = new JFXPanel(); Platform.runLater(() -> { Button button = new Button("Alert"); button.setOnAction(evt -> { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setHeaderText("An Alert"); alert.setContentText("Alerting"); alert.initModality(Modality.APPLICATION_MODAL); alert.initOwner(button.getScene().getWindow()); alert.initStyle(StageStyle.UTILITY); alert.show(); }); BorderPane borderPane = new BorderPane(); borderPane.setCenter(button); Scene scene = new Scene(borderPane, 300, 300); SwingUtilities.invokeLater(() -> { fxPanel.setScene(scene); JFrame frame = new JFrame("App"); frame.add(fxPanel); frame.setSize(300, 300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }); });
I understand that when a window link is used in this code alert.initOwner(button.getScene().getWindow()); , the object com.sun.javafx.stage.EmbeddedWindow returned. I know that it would be impossible to take JFrame as the owner of the Alert window. But are there any hacks to make this happen?
source share