import java.util.Timer; import java.util.TimerTask; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class SwingTest { private static final String URL = "http://netbeans.org/features/platform/features.html"; private static final double MIN_ZOOM = .1; // 1.0 means 100% private static final double MAX_ZOOM = 2; private static final long DELAY = 2000; // ms static int n = 0; private static JFXPanel javafxPanel; private static void initAndShowGUI() { final JFrame frame = new JFrame("Swing application"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); javafxPanel = new JFXPanel(); frame.getContentPane().add(javafxPanel); Platform.runLater(new Runnable() { public void run() { javafxPanel.setScene(createScene()); SwingUtilities.invokeLater(new Runnable() { public void run() { frame.pack(); frame.setVisible(true); } }); } }); } private static Scene createScene() { final WebView webView = new WebView(); final WebEngine webEngine = webView.getEngine(); webEngine.load(URL); Scene scene = new Scene(webView); TimerTask task = new TimerTask() { @Override public void run() { Platform.runLater(new Runnable() { public void run() { webView.setZoom(MIN_ZOOM + Math.random() * (MAX_ZOOM - MIN_ZOOM)); System.out.println(++n + " webView.getZoom() = " + webView.getZoom()); } }); } }; new Timer(true).schedule(task, 10000, DELAY); return scene; } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { initAndShowGUI(); } }); } }