package javafxsamples; import javafx.application.Application; import javafx.beans.value.InvalidationListener; import javafx.beans.value.ObservableValue; import javafx.builders.SplitPaneBuilder; import javafx.builders.TextBoxBuilder; import javafx.builders.VBoxBuilder; import javafx.geometry.Orientation; import javafx.scene.Scene; import javafx.scene.control.ListView; import javafx.scene.control.SplitPane; import javafx.scene.control.TextBox; import javafx.scene.layout.VBox; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import javafx.stage.Stage; /** * * @author Alex */ public class WebApp extends Application { final String mainUrl = "http://www.google.com"; final String searchUrl = mainUrl + "/search?q="; TextBox mainTextBox; TextBox searchTextBox; WebView webView; WebEngine webEngine; ListView navListView; public WebApp() { } @Override public void start(Stage primaryStage) throws Exception { webEngine = new WebEngine(mainUrl); webEngine.locationProperty().addListener(new InvalidationListener() { @Override public void invalidated(ObservableValue observable) { String url = observable.getValue(); mainTextBox.setText(url); if (!navListView.getItems().contains(url)) { navListView.getItems().add(url); } } }); webView = new WebView(webEngine); mainTextBox = new TextBoxBuilder().text(mainUrl).build(); searchTextBox = new TextBoxBuilder().build(); mainTextBox.setAction(new Runnable() { @Override public void run() { navTo(mainTextBox.getText()); } }); searchTextBox.setAction(new Runnable() { @Override public void run() { navTo(searchUrl + searchTextBox.getText()); } }); navListView = new ListView(); navListView.getSelectionModel().selectedItemProperty().addListener(new InvalidationListener() { @Override public void invalidated(ObservableValue observable) { String url = observable.getValue().toString(); navTo(url); } }); SplitPane splitPaneNav = new SplitPaneBuilder() .items(mainTextBox, searchTextBox).build(); splitPaneNav.setDividerPosition(0, .8); SplitPane pane = new SplitPaneBuilder().orientation(Orientation.VERTICAL).items(navListView, webView).build(); pane.setDividerPosition(0, .2); final VBox mainBox = new VBoxBuilder().spacing(5).children(splitPaneNav, pane).build(); Scene s = new Scene(mainBox, 600, 500); primaryStage.setScene(s); primaryStage.setVisible(true); } void navTo(String url){ mainTextBox.setText(url); webEngine.load(url); } public static void main(String[] args) { launch(args); } }