Results 1 to 2 of 2
  1. #1
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    MA, USA
    Rep Power

    Default WebEngine callback

    JavaFX offers the WebEngine that shall load webpages in the background and offers callbacks when the status has changed. Somehow I have issues with the callback, maybe you guys can take a look at the code below.
    The first part has the WebEngine portion, it establishes the callback and the state changes twice. But then it gets stuck somewhere and it seems it never changes its state to SUCCEEDED.
    The second portion (commented out for now) loads the same URL and seems to work. In order to compare the time you have to comment out the first portion and un-comment the second portion.
    Any help is appreciated.
    p.s.: i you get some strange messages with the second portion in the comment section: this is a bug to be resolved in Java 9.

    Java FX Code:
    package webEngine;
    import javafx.application.Application;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.concurrent.Worker;
    import javafx.concurrent.Worker.State;
    import javafx.scene.Scene;
    import javafx.scene.web.WebEngine;
    import javafx.scene.web.WebView;
    import javafx.stage.Stage;
    public class webEngineMain extends Application {
    	public void start(Stage primaryStage) {
    		//webengine process
    		final WebEngine webEngine = new WebEngine();			
    				new ChangeListener<State>(){
    					public void changed(
    							ObservableValue observable,
    							State oldValue, State newValue) {
    						System.out.println("state change from " + oldValue.toString() + " to " + newValue.toString());
    							System.out.println("document finished loading");
    		System.out.println("loading started");
    		//webview process
    		WebView webview = new WebView();
    		Scene scene = new Scene(webview, 800,200);
    	public static void main(String[] args) {

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    MA, USA
    Rep Power

    Default Re: WebEngine callback

    I found a solution and wanted to wrap up this thread:
    the Worker Interface States can be found here

    The State of the Worker changes to SUCCEEDED if you have a WebView and you actually show the webpage on the scene. I am not sure why the snippet above did not change the State to SUCCEEDED, I would guess that the main thread exited (ahead of the background thread) since we did not show anything on any stage.

    I am not sure how easy the Mods are about posting large amounts of code, but I can post a compiling and working code of a fxml browser that shows the status changes, just let me know.

Similar Threads

  1. Callback Methods
    By Nazneen Ali in forum New To Java
    Replies: 4
    Last Post: 10-28-2013, 11:33 AM
  2. Non blocking callback method
    By Bibhukalyana in forum New To Java
    Replies: 4
    Last Post: 04-11-2013, 07:53 PM
  3. use api without callback url?
    By Seiya0890 in forum New To Java
    Replies: 0
    Last Post: 03-02-2013, 06:02 PM
  4. query with a callback?
    By Filobel in forum JDBC
    Replies: 4
    Last Post: 01-20-2012, 10:33 AM
  5. WebEngine find text
    By PhQ in forum JavaFX
    Replies: 6
    Last Post: 09-15-2011, 09:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts