import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.web.WebEvent; import javafx.scene.web.WebView; import javafx.stage.Stage; import javax.swing.*; public class Test { public static void start(JFXPanel t) { Group g = new Group(); final Scene s = new Scene(g); final WebView w = new WebView(); g.getChildren().add(w); w.getEngine().setOnAlert(new EventHandler>() { @Override public void handle(WebEvent event) { Stage p = new Stage(); p.initOwner(s.getWindow()); p.setScene(new Scene(new Group(), Color.RED)); p.setWidth(400); p.setHeight(400); p.showAndWait(); } }); w.getEngine().loadContent(""); t.setScene(s); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame f = new JFrame("F"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setBounds(100, 100, 320, 240); final JFXPanel p = new JFXPanel(); f.getContentPane().add(p); f.setVisible(true); Platform.runLater(new Runnable() { @Override public void run() { start(p); } }); } }); } }