List of usage examples for javafx.scene.web WebView WebView
public WebView()
From source file:clientechat.TestList.java
@Override public void start(Stage primaryStage) { WebView wv = new WebView(); Button btn = new Button(); TextField textField = new TextField(); VBox vb = new VBox(); WebEngine appendEngine = wv.getEngine(); btn.setOnAction(new EventHandler<ActionEvent>() { @Override//from ww w. j a v a2 s. c o m public void handle(ActionEvent event) { executejQuery(appendEngine, "$('#content').append(\"<p align=right><b>World!" + escapeHtml(textField.getText()) + "<b><p>\");"); executejQuery(appendEngine, "$(\"html, body\").animate({ scrollTop: $(document).height()-$(window).height() });"); } }); wv.getEngine().loadContent( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + "<head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" + "<title>Documento sin ttulo</title>\n" + "</head>\n" + "\n" + "<body id=\"content\">\n" + " \n" + "</body>\n" + "</html>"); vb.getChildren().addAll(wv, btn, textField); Scene scene = new Scene(vb); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); }
From source file:org.geopoke.WorldMap.java
public WorldMap() { markers = new HashSet<>(); ready = false;//from w ww . jav a 2 s. c o m webview = new WebView(); try { webview.getEngine().load(new File("googlemap.html").toURI().toURL().toString()); } catch (MalformedURLException ex) { ex.printStackTrace(); } setCenter(webview); webview.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() { @Override public void changed(ObservableValue ov, Worker.State t, Worker.State t1) { if (t1.equals(Worker.State.SUCCEEDED)) { ready = true; } } }); }
From source file:view.TimelinePanel.java
/** * Creates new form TimelinePanel// w w w . j av a 2 s . c o m */ public TimelinePanel() { initComponents(); fxPanel = new JFXPanel(); final Dimension size = new Dimension(960, 750); fxPanel.setSize(size); setLayout(new BorderLayout(0, 0)); add(fxPanel); Platform.runLater(new Runnable() { // this will run initFX as JavaFX-Thread @Override public void run() { Group group = new Group(); Scene scene = new Scene(group); fxPanel.setScene(scene); WebView webView = new WebView(); group.getChildren().add(webView); webView.setMinSize(size.getWidth(), size.getHeight()); webView.setMaxSize(size.getWidth(), size.getHeight()); WebEngine webEngine = webView.getEngine(); webEngine.load( "http://cdn.knightlab.com/libs/timeline/latest/embed/index.html?source=0Ag1_iE674IuvdEFaZi0wOVBFY2l2OHdPUWlrZEMwaHc&font=Bevan-PotanoSans&maptype=toner&lang=en"); } }); }
From source file:io.uploader.drive.auth.webbrowser.SimpleBrowserImpl.java
public SimpleBrowserImpl(Stage stage, String url) throws IOException { super();/* ww w .j a v a 2s . c o m*/ Preconditions.checkNotNull(stage); this.stage = stage; stage.setTitle("Drive Uploader - Authentication"); UiUtils.setStageAppSize(stage); Scene scene = new Scene(new Group()); AnchorPane root = new AnchorPane(); final WebView browser = new WebView(); webEngine = browser.getEngine(); /* Menu settingsMenu = new Menu ("Settings") ; MenuItem proxy = new MenuItem ("Proxy") ; settingsMenu.getItems().add(proxy) ; MenuBar menuBar = new MenuBar () ; menuBar.getMenus().add(settingsMenu) ; proxy.setOnAction(new EventHandler<ActionEvent> () { @Override public void handle(ActionEvent event) { try { ProxySettingDialog dlg = new ProxySettingDialog (stage, Configuration.INSTANCE) ; dlg.showDialog(); } catch (IOException e) { logger.error("Error occurred while opening the proxy setting dialog", e); } }});*/ FXMLLoader mainMenuLoader = new FXMLLoader(getClass().getResource("/fxml/MainMenu.fxml")); VBox mainMenuBar = (VBox) mainMenuLoader.load(); AnchorPane.setTopAnchor(mainMenuBar, 0.0); AnchorPane.setLeftAnchor(mainMenuBar, 0.0); AnchorPane.setRightAnchor(mainMenuBar, 0.0); MainMenuController mainMenuController = mainMenuLoader.<MainMenuController>getController(); mainMenuController.setOwner(stage); mainMenuController.setConfiguration(Configuration.INSTANCE); mainMenuController.hideAccountMenu(true); ScrollPane scrollPane = new ScrollPane(); scrollPane.setContent(browser); scrollPane.setFitToWidth(true); scrollPane.setFitToHeight(true); if (StringUtils.isNotEmpty(url)) { goTo(url); } if (DriveUploader.isMacOsX()) { AnchorPane.setTopAnchor(scrollPane, 5.0); } else { AnchorPane.setTopAnchor(scrollPane, 35.0); } AnchorPane.setLeftAnchor(scrollPane, 5.0); AnchorPane.setRightAnchor(scrollPane, 5.0); AnchorPane.setBottomAnchor(scrollPane, 5.0); root.getChildren().add(mainMenuBar); root.getChildren().addAll(scrollPane); scene.setRoot(root); stage.setScene(scene); }
From source file:net.sf.anathema.framework.presenter.action.about.AnathemaAboutAction.java
@SuppressWarnings("ConstantConditions") private void showCredits(MigPane parent) { try {/*from ww w. j a v a 2 s. com*/ InputStream content = getClass().getClassLoader().getResourceAsStream("about.md"); URL stylesheet = getClass().getClassLoader().getResource("aboutPage.css"); String markdownContent = IOUtils.toString(content); HtmlText htmlText = new HtmlConverter().convert(new WikiText(markdownContent)); final WebView webView = new WebView(); webView.getEngine().setUserStyleSheetLocation(stylesheet.toExternalForm()); webView.getEngine().loadContent(htmlText.getHtmlText()); parent.add(webView, new CC().pad(0, 2, 0, 2)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.ks.text.view.AsciiDocViewer.java
@Override public void initialize(URL location, ResourceBundle resources) { CompletableFuture.supplyAsync(() -> new WebView(), controller.getJavaFXExecutor()).thenAccept(view -> { webView = view;/* www . java 2 s . c o m*/ webView.setMinSize(100, 100); webView.setPrefSize(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE); root.getChildren().add(webView); }); Iterator<AsciiDocPreProcessor> iterator = preProcessorProvider.iterator(); while (iterator.hasNext()) { AsciiDocPreProcessor next = iterator.next(); addPreProcessor(next); } }
From source file:gisintegration.SimpleSwingBrowser.java
private void createScene() { Platform.runLater(new Runnable() { @Override//from www . j ava 2 s . com public void run() { WebView view = new WebView(); engine = view.getEngine(); // engine.titleProperty().addListener(new ChangeListener<String>() { // @Override // public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) { // SwingUtilities.invokeLater(new Runnable() { // @Override // public void run() { // SimpleSwingBrowser.this.setTitle(newValue); // } // }); // } // }); engine.setOnStatusChanged(new EventHandler<WebEvent<String>>() { @Override public void handle(final WebEvent<String> event) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { lblStatus.setText(event.getData()); } }); } }); // engine.locationProperty().addListener(new ChangeListener<String>() { // @Override // public void changed(ObservableValue<? extends String> ov, String oldValue, final String newValue) { // SwingUtilities.invokeLater(new Runnable() { // @Override // public void run() { // txtURL.setText(newValue); // } // }); // } // }); engine.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, final Number newValue) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { progressBar.setValue(newValue.intValue()); } }); } }); engine.getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() { public void changed(ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) { if (engine.getLoadWorker().getState() == FAILED) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JOptionPane.showMessageDialog(panel, (value != null) ? engine.getLocation() + "\n" + value.getMessage() : engine.getLocation() + "\nUnexpected error.", "Loading error...", JOptionPane.ERROR_MESSAGE); } }); } } }); jfxPanel.setScene(new Scene(view)); } }); }
From source file:utybo.branchingstorytree.swing.visuals.NodePanel.java
public NodePanel(BranchingStory story, StoryPanel parent, final IMGClient imageClient) { OpenBSTGUI.getInstance().addDarkModeCallback(callback); callback.accept(OpenBSTGUI.getInstance().isDark()); this.parent = parent; this.imageClient = imageClient; setLayout(new BorderLayout()); JFXPanel panel = new JFXPanel(); add(panel, BorderLayout.CENTER); CountDownLatch cdl = new CountDownLatch(1); Platform.runLater(() -> {//from ww w .j av a2s . co m try { view = new WebView(); view.getEngine().setOnAlert(e -> SwingUtilities .invokeLater(() -> Messagers.showMessage(OpenBSTGUI.getInstance(), e.getData()))); view.getEngine().getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> { if (newState == State.SUCCEEDED) { Document doc = view.getEngine().getDocument(); NodeList nl = doc.getElementsByTagName("a"); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); HTMLAnchorElement a = (HTMLAnchorElement) n; if (a.getHref() != null) { ((EventTarget) a).addEventListener("click", ev -> { if (!hrefEnabled) { ev.preventDefault(); } }, false); } } } }); Scene sc = new Scene(view); try { view.getEngine() .loadContent(IOUtils .toString( NodePanel.class.getResourceAsStream( "/utybo/branchingstorytree/swing/html/error.html"), StandardCharsets.UTF_8) .replace("$MSG", Lang.get("story.problem")).replace("$STYLE", FONT_UBUNTU)); } catch (IOException e) { OpenBST.LOG.warn("Error on trying to load error HTML file", e); } panel.setScene(sc); } finally { cdl.countDown(); } }); try { cdl.await(); } catch (InterruptedException e) { OpenBST.LOG.warn("Synchronization failed", e); } }
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); });/*from w w w. jav a2 s . c om*/ 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
private void createClipList(GridPane grid) { final VBox vbox = new VBox(30); vbox.setAlignment(Pos.TOP_CENTER);/*from w w w .j a v a 2s . co m*/ final Label clipLabel = new Label("Code Monkey To-Do List:"); clipLabel.setId("clipLabel"); final Button getUpButton = new Button("Get Up, Get Coffee"); getUpButton.setPrefWidth(300); getUpButton.setOnAction(createPlayHandler(coffeeClip)); final Button goToJobButton = new Button("Go to Job"); goToJobButton.setPrefWidth(300); goToJobButton.setOnAction(createPlayHandler(jobClip)); final Button meetingButton = new Button("Have Boring Meeting"); meetingButton.setPrefWidth(300); meetingButton.setOnAction(createPlayHandler(meetingClip)); final Hyperlink link = new Hyperlink("About Code Monkey..."); link.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { WebView wv = new WebView(); wv.getEngine().load("http://www.jonathancoulton.com/2006/04/14/" + "thing-a-week-29-code-monkey/"); Scene scene = new Scene(wv, 720, 480); Stage stage = new Stage(); stage.setTitle("Code Monkey"); stage.setScene(scene); stage.show(); } }); vbox.getChildren().addAll(clipLabel, getUpButton, goToJobButton, meetingButton, link); GridPane.setHalignment(vbox, HPos.CENTER); GridPane.setHgrow(vbox, Priority.ALWAYS); GridPane.setVgrow(vbox, Priority.ALWAYS); grid.add(vbox, 0, 0, GridPane.REMAINING, 1); }