Note that there are some explanatory texts on larger screens.

plurals
  1. POUpcall Javascript to JavaFX
    primarykey
    data
    text
    <p>I want to learn more about JavaFX and so I tried to set up Webview. I copied the webview example from the Oracle website and added Upcall functionality. But it isn't working. Actually I have no idea how to debug a website in Webview. So here is the java code:</p> <pre><code>package boersensim; import javafx.application.Application; import javafx.application.Platform; import javafx.geometry.HPos; import javafx.geometry.VPos; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.Region; import javafx.scene.paint.Color; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import javafx.stage.Stage; import netscape.javascript.JSObject; public class Main extends Application { private Scene scene; @Override public void start(Stage stage) { // create the scene stage.setTitle("Web View"); scene = new Scene(new Browser(),750,500, Color.web("#666970")); stage.setScene(scene); //scene.getStylesheets().add("webviewsample/BrowserToolbar.css"); stage.show(); } public static void main(String[] args){ launch(args); } } class Browser extends Region { final WebView browser = new WebView(); final WebEngine webEngine = browser.getEngine(); public Browser() { //apply the styles getStyleClass().add("browser"); // load the web page webEngine.load("test.html"); //add the web view to the scene getChildren().add(browser); JSObject jsobj = (JSObject) webEngine.executeScript("window"); jsobj.setMember("java", new Bridge()); } private Node createSpacer() { Region spacer = new Region(); HBox.setHgrow(spacer, Priority.ALWAYS); return spacer; } @Override protected void layoutChildren() { double w = getWidth(); double h = getHeight(); layoutInArea(browser,0,0,w,h,0, HPos.CENTER, VPos.CENTER); } @Override protected double computePrefWidth(double height) { return 750; } @Override protected double computePrefHeight(double width) { return 500; } } class Bridge { public void exit() { //Platform.exit(); System.out.print("Hello!UPCALL"); } } </code></pre> <p>The corrosponding HTML is:</p> <pre><code>Click&lt;a href="#" onclick="java.exit();"&gt;here&lt;/a&gt;to exit the application </code></pre> <p>When I click the link nothing happens.</p> <p>Thanks to you in advance, Daniel </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload