JavaFX 8 WebEngine: How to get console.log() from javascript to System.out in java?

The following code redirects console.log() to JavaBridge.log(): import netscape.javascript.JSObject; […] public class JavaBridge { public void log(String text) { System.out.println(text); } } // Maintain a strong reference to prevent garbage collection: // https://bugs.openjdk.java.net/browse/JDK-8154127 private final JavaBridge bridge = new JavaBridge(); […] webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> { JSObject window = (JSObject) webEngine.executeScript(“window”); window.setMember(“java”, bridge); webEngine.executeScript(“console.log = … Read more

How to call launch() more than once in java

You can’t call launch() on a JavaFX application more than once, it’s not allowed. From the javadoc: It must not be called more than once or an exception will be thrown. Suggestion for showing a window periodically Just call Application.launch() once. Keep the JavaFX runtime running in the background using Platform.setImplicitExit(false), so that JavaFX does … Read more