Example usage for javafx.scene.web WebHistory getEntries

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

Introduction

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

Prototype

public ObservableList<Entry> getEntries() 

Source Link

Document

Returns an unmodifiable observable list of all entries in the history.

Usage

From source file:Main.java

@Override
public void start(final Stage stage) {
    stage.setWidth(400);//from   www.  j  a  va  2 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();
}