I have a swing application and have to integrate new javafx FXML files into it. I use a JFXPanel to open my FXML form. The exit button is created on the FXML form. My controller class implements the event of that button. But how do I close the Jframe from my swing application?
My JavaFX Controller class (method)
@FXML
private void doExit(ActionEvent event) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Stage stage = (Stage) btnExit.getScene().getWindow();
stage.close();
}
});
}
Swing application start load my JFXPanel
JFrame frame = new JFrame("");
frame.setLayout(new BorderLayout());
final JFXPanel jfxPanel = new JFXPanel();
frame.add(jfxPanel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(true);
SwingUtilities.invokeLater(() -> initPrijsMutatieFX(jfxPanel));