Example usage for javafx.scene.web WebView getEngine

List of usage examples for javafx.scene.web WebView getEngine

Introduction

In this page you can find the example usage for javafx.scene.web WebView getEngine.

Prototype

public final WebEngine getEngine() 

Source Link

Document

Returns the WebEngine object.

Usage

From source file:org.openbase.display.WebTab.java

private static WebView newWebView() {
    logger.info("init new WebView...");
    WebView webView = new WebView();
    WebEngine webEngine = webView.getEngine();
    webEngine.setJavaScriptEnabled(true);
    webEngine.setOnAlert((WebEvent<String> event) -> {
        ExceptionPrinter.printHistory(new InvalidStateException("Webengine alert detected!",
                new CouldNotPerformException(event.toString())), logger);
    });/*  w ww  .  j  av  a2 s .c o  m*/
    webEngine.setOnError((WebErrorEvent event) -> {
        ExceptionPrinter.printHistory(new InvalidStateException("Webengine error detected!",
                new CouldNotPerformException(event.toString())), logger);
    });
    webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends Worker.State> observable,
            Worker.State oldValue, Worker.State newState) -> {
        Throwable exception = webEngine.getLoadWorker().getException();
        if (exception != null && newState == Worker.State.FAILED) {
            ExceptionPrinter.printHistory(new InvalidStateException("Webengine exception detected!", exception),
                    logger);
        }
    });

    CookieManager.getDefault();
    return webView;
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    vb.setId("root");

    WebView browser = new WebView();
    WebEngine engine = browser.getEngine();
    String url = "http://java2s.com/";
    engine.load(url);//from ww w  . j  av  a 2  s .  c  o  m

    vb.setPadding(new Insets(30, 50, 50, 50));
    vb.setSpacing(10);
    vb.setAlignment(Pos.CENTER);
    vb.getChildren().addAll(browser);

    Scene scene = new Scene(vb);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

License:asdf

@Override
public void start(Stage stage) {
    stage.setWidth(500);//w  w w.  j a  va  2 s .  c om
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    VBox root = new VBox();

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(browser);
    webEngine.loadContent("<b>asdf</b>");

    root.getChildren().addAll(scrollPane);
    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

License:asdf

@Override
public void start(Stage stage) {
    stage.setTitle("HTML");
    stage.setWidth(500);//from  w  w  w .  jav  a  2 s  .c o m
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    VBox root = new VBox();

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(browser);
    webEngine.loadContent("<b>asdf</b>");

    root.getChildren().addAll(scrollPane);
    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(final Stage stage) {
    stage.setWidth(400);/*from  w w w .j av a 2  s.  co  m*/
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(browser);

    browser.getEngine().setOnAlert((WebEvent<String> wEvent) -> {
        System.out.println("Alert Event  -  Message:  " + wEvent.getData());
    });

    webEngine.load("http://java2s.com");

    scene.setRoot(scrollPane);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

License:asdf

@Override
public void start(Stage stage) {
    stage.setWidth(500);/* www. j  av  a2 s.c om*/
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    VBox root = new VBox();

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setFitToWidth(true);

    scrollPane.setContent(browser);
    webEngine.loadContent("<b>asdf</b>");

    root.getChildren().addAll(scrollPane);
    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

License:asdf

@Override
public void start(Stage stage) {
    stage.setTitle("HTML");
    stage.setWidth(500);//from ww  w  .j  av a 2 s  .c om
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    VBox root = new VBox();

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setStyle("-fx-background-color: white");

    scrollPane.setContent(browser);
    webEngine.loadContent("<b>asdf</b>");

    root.getChildren().addAll(scrollPane);
    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("HTML");
    stage.setWidth(500);//  w w  w .jav a  2 s.  co  m
    stage.setHeight(500);
    Scene scene = new Scene(new Group());
    VBox root = new VBox();
    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();
    Hyperlink hpl = new Hyperlink("java2s.com");
    hpl.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            webEngine.load("http://java2s.com");
        }
    });

    root.getChildren().addAll(hpl, browser);
    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

License:asdf

@Override
public void start(final Stage stage) {
    stage.setTitle("HTML");
    stage.setWidth(500);//from  w w  w. j  ava2 s.c  o  m
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    VBox root = new VBox();

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(browser);

    webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
        @Override
        public void changed(ObservableValue ov, State oldState, State newState) {

            if (newState == Worker.State.SUCCEEDED) {
                stage.setTitle(webEngine.getLocation());
                System.out.println("called");
            }

        }
    });
    webEngine.load("http://javafx.com");

    webEngine.loadContent("<b>asdf</b>");

    root.getChildren().addAll(scrollPane);
    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(final Stage stage) {
    stage.setWidth(400);//w  ww.  j a v a2 s.  c o m
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(browser);

    browser.getEngine().setOnAlert((WebEvent<String> wEvent) -> {
        System.out.println("Alert Event  -  Message:  " + wEvent.getData());
    });

    webEngine.load("http://java2s.com");

    final WebHistory history = webEngine.getHistory();
    history.getEntries().addListener(new ListChangeListener<WebHistory.Entry>() {
        @Override
        public void onChanged(Change<? extends Entry> c) {
            c.next();
            for (Entry e : c.getRemoved()) {
                System.out.println(e.getUrl());
            }
            for (Entry e : c.getAddedSubList()) {
                System.out.println(e.getUrl());
            }
        }
    });

    history.go(0);
    scene.setRoot(scrollPane);

    stage.setScene(scene);
    stage.show();
}