Execution environment for javafx.scene.web

Kevin Rushforth kevin.rushforth at oracle.com
Fri Feb 6 15:44:25 UTC 2015


Additionally, if you aren't going to display the primary Stage in the 
Application start(Stage) method then I also recommend you call:

Platform.setImplicitExit(false);

in the start method, since you will need to control the life-cycle of 
the application yourself and call Platform.exit() to exit the FX runtime.

-- Kevin


Anton Tarasov wrote:
> Hi Michael,
>
> Yes, WebEngine can be used separately from WebView.
>
> (See inline, please)
>
> On 05/02/15 02:53, Michael Pozhidaev wrote:
>> Hello everybody,
>>
>> I am working on the technology representing the information in form
>> which adjusted to the perception of blind people. It is just as
>> an addition to usual screen readers.
>>
>> For a long time there was a rather big problem, it is a web browsing. My
>> environment is implemented in Java but I was unable to get any web
>> browser features.Any web surfing activity was possible only if you are
>> using a fully functional browser, like Firefox, Chrome, etc.
>>
>>  From time to time I looked for any browser implementations in Java but
>> everything what I got  never looked interesting. The picture totally
>> changed when I found javafx.scene.web. At a glance it looks like exactly
>> what I need!
>>
>> The key feature which looks nice to me is a splitting a visualization 
>> and
>> a background engine. I need exactly the engine which manages DOM, can
>> execute JavaScript, sends all notifications and events, but don't take
>> care about graphical representation. The description for WebEngine class
>> says that it suits completely.
>>
>> OK, but I would like to ensure that JavaFX itself suits as well. 
>> Meaning, may I
>> use WebEngine class without creating _*graphical*_ application? In other
>> words, what should the execution environment for WebEngine be?
>>
>> There are two questions I would like to understand:
>>
>> 1. Should I create a full graphical application in JavaFX traditions to
>> be able to use WebEngine? My application uses a speech feedback as a
>> main way to bring information to users. If it is required that I should
>> have a complete graphical scene for using WebEngine it would be bad news
>> for me.
>
> Well, you need to create a JavaFX application in order to start using 
> WebEngine,
> but you don't need to display any GUI (Stage, Scene etc.) on the screen.
>
> If that works for you, then basicly it may look as follows:
>
> import javafx.application.Application;
> import javafx.scene.web.WebEngine;
> import javafx.stage.Stage;
> import javafx.beans.value.ChangeListener;
> import javafx.beans.value.ObservableValue;
> import javafx.concurrent.Worker.State;
>
> public class MyWebApp extends Application {
>     static WebEngine web;
>
>     public MyWebApp() {}
>
>     public void start(Stage s) {
>         web = new WebEngine();
>         web.getLoadWorker().stateProperty().addListener(
>             new ChangeListener<State>() {
>                 public void changed(ObservableValue ov, State 
> oldState, State newState) {
>                     if (newState == State.SUCCEEDED) {
>                         System.out.println(web.getTitle());
>                     }
>                 }
>             });
>         web.load("http://javafx.com");
>     }
> }
>
> The "start" method is your entry point into the JavaFX App thread.
> That's where WebEngine must be created and managed, and you can't do 
> it anywhere else
> (that's why you need a JavaFX app even if you don't plan to use any 
> GUI stuff).
>
> You may also launch a JavaFX app tradittionally, via the "main" method:
>
> import javafx.application.Application;
>
> public class Main {
>     public static void main(String[] args) {
>         Application.launch(MyWebApp.class, args);
>     }
> }
>
> The "launch" method won't return untill JavaFX has exited, so you need 
> to start your base logic (start your worker threads) before this call.
>
> The way you access your WebEngine instance is either via its 
> associated listeners or via Platform.runLater():
>
> Platform.runLater(new Runnable() {
> public void run() {
>          System.out.println(MyWebApp.web.getLocation());
>      }
> });
>
> Both ways you do it on the JavaFX App thread.
>
> One more thing is that you should prevent JavaFX from auto-exit. This 
> happens after the last Stage is closed.
> As you don't have any Stage open, you should tell JavaFX that you want 
> it to continue until you explicitly request it to exit.
>
> This is what you need to call first from the "start" method:
>
> Platform.setImplicitExit(false);
>
> (Actually, WebEngine itself should prevent JavaFX from auto-exit, but 
> you're better to do that explicitly.)
>
>> 2. Do I understand correctly that JavaFX applications are able to be
>> launched just in Java Virtual Machine? Meaning, they do not need a
>> complete web browser, right? I found that javafx.scene.web using
>> webkit and it is OK. I am asking that the user shouldn't need opening 
>> a web
>> browser window and run JavaFX application in it, yes?
>
> What you're telling about is the "applet mode". You're not limited to 
> it. You can launch your JavaFX app as a standlone application.
> So, you don't need to open a browser.
>
>>
>> Help me please! If these questions would be OK I would be able to
>> significantly improve my environment!
>>
>> Thank you in advance! :))
>
> You're welcome!
>
> Regards,
> Anton.
>


More information about the openjfx-dev mailing list