Example usage for javafx.scene.web WebHistory go

List of usage examples for javafx.scene.web WebHistory go

Introduction

In this page you can find the example usage for javafx.scene.web WebHistory go.

Prototype

public void go(int offset) throws IndexOutOfBoundsException 

Source Link

Document

Navigates the web engine to the URL defined by the Entry object within the specified position relative to the current entry.

Usage

From source file:Main.java

@Override
public void start(final Stage stage) {
    stage.setWidth(400);/*from   w  w w.  j  a v a 2  s. c om*/
    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();
}