public static void showAndWait(String url, Predicate<WebEngine> loginSuccessTest, Consumer<WebEngine> handler) { try { FXMLLoader loader = new FXMLLoader(LoginController.class.getResource("/fxml/login.fxml")); Stage stage = new Stage(); stage.setScene(new Scene(loader.load())); LoginController controller = loader.<LoginController>getController(); controller.setUrl(url); controller.setLoginSuccessTest(loginSuccessTest); controller.setHandler(handler); stage.setTitle("Login..."); stage.initModality(Modality.APPLICATION_MODAL); stage.showAndWait(); } catch (IOException ex) { throw new RuntimeException(ex); } }
@Override public void start(Stage stage) { stage.setTitle("HTMLEditor Sample"); stage.setWidth(650); stage.setHeight(500); Scene scene = new Scene(new Group()); VBox root = new VBox(); root.setPadding(new Insets(8, 8, 8, 8)); root.setSpacing(5); root.setAlignment(Pos.BOTTOM_LEFT); final HTMLEditor htmlEditor = new HTMLEditor(); htmlEditor.setPrefHeight(245); htmlEditor.setHtmlText(INITIAL_TEXT); final WebView browser = new WebView(); final WebEngine webEngine = browser.getEngine(); ScrollPane scrollPane = new ScrollPane(); scrollPane.getStyleClass().add("noborder-scroll-pane"); scrollPane.setStyle("-fx-background-color: white"); scrollPane.setContent(browser); scrollPane.setFitToWidth(true); scrollPane.setPrefHeight(180); Button showHTMLButton = new Button("Load Content in Browser"); root.setAlignment(Pos.CENTER); showHTMLButton.setOnAction((ActionEvent arg0) -> { webEngine.loadContent(htmlEditor.getHtmlText()); }); root.getChildren().addAll(htmlEditor, showHTMLButton, scrollPane); scene.setRoot(root); stage.setScene(scene); stage.show(); }
private EventHandler<WebEvent<String>> createEventHandler() { return new EventHandler<WebEvent<String>>() { @Override public void handle(WebEvent<String> event) { if (event.getSource() instanceof WebEngine) { WebEngine engine = (WebEngine) event.getSource(); String url = engine.getLocation(); String code = getResponseValueFromUrl(url); if (StringUtils.isNotEmpty(code)) { webEngine.getLoadWorker().cancel(); startCreateOAuth(code); } } } }; }
private void initComponents() { webView.setId("webView"); webView.getEngine().getLoadWorker().stateProperty().addListener(new HyperlinkRedirectListener(webView)); VBox.setVgrow(webView, Priority.ALWAYS); WebEngine engine = webView.getEngine(); if (blurbInfo.getURL() != null) engine.load(blurbInfo.getURL().toExternalForm()); else engine.loadContent(blurbInfo.getHtml()); buttonBar.setId("buttonBar"); buttonBar.setButtonMinWidth(Region.USE_PREF_SIZE); buttonBar.getButtons().add(okButton); if (blurbInfo.isCancelNeeded()) { buttonBar.getButtons().add(cancelButton); } okButton.setOnAction((e) -> onOk()); cancelButton.setOnAction((e) -> onCancel()); }
@Override public void start(Stage stage) { VBox vbox = new VBox(); Scene scene = new Scene(vbox); stage.setTitle("Hyperlink Sample"); stage.setWidth(570); stage.setHeight(550); selectedImage.setLayoutX(100); selectedImage.setLayoutY(10); final WebView browser = new WebView(); final WebEngine webEngine = browser.getEngine(); for (int i = 0; i < captions.length; i++) { final Hyperlink hpl = hpls[i] = new Hyperlink(captions[i]); final Image image = images[i] = new Image(getClass().getResourceAsStream(imageFiles[i])); hpl.setGraphic(new ImageView (image)); hpl.setFont(Font.font("Arial", 14)); final String url = urls[i]; hpl.setOnAction((ActionEvent e) -> { webEngine.load(url); }); } HBox hbox = new HBox(); hbox.setAlignment(Pos.BASELINE_CENTER); hbox.getChildren().addAll(hpls); vbox.getChildren().addAll(hbox, browser); VBox.setVgrow(browser, Priority.ALWAYS); stage.setScene(scene); stage.show(); }
public void showOverview() { if (!manager.isCatalogueLoaded() || (manager.groupList() == null || manager.groupList().isEmpty())) { return; } SimpleOverviewBuilder overview = new SimpleOverviewBuilder(manager.getCatalogue(), manager.groupList()); String export = overview.exportOverviewHTML(); WebView view = new WebView(); WebEngine engine = view.getEngine(); engine.loadContent(export); HBox box = new HBox(); view.prefWidthProperty().bind(box.widthProperty()); view.prefHeightProperty().bind(box.heightProperty()); Scene webScene = new Scene(box, evaluator.getWidth(), evaluator.getHeight()); box.prefWidthProperty().bind(webScene.widthProperty()); box.prefHeightProperty().bind(webScene.heightProperty()); box.getChildren().add(view); PopupStage popupStage = new PopupStage("Overview", webScene); popupStage.showAndWait(); }
private SplitPane createChartPane() { CategoryDataset3D dataset = SampleData.createCompanyRevenueDataset(); Chart3D chart = AreaChart3DFXDemo1.createChart(dataset); Chart3DViewer viewer = new Chart3DViewer(chart); this.splitter = new SplitPane(); splitter.setOrientation(Orientation.VERTICAL); final BorderPane borderPane = new BorderPane(); borderPane.setCenter(viewer); // Bind canvas size to stack pane size. viewer.prefWidthProperty().bind(borderPane.widthProperty()); viewer.prefHeightProperty().bind(borderPane.heightProperty()); final StackPane sp2 = new StackPane(); this.chartDescription = new WebView(); WebEngine webEngine = chartDescription.getEngine(); webEngine.load(AreaChart3DFXDemo1.class.getResource("AreaChart3DFXDemo1.html").toString()); sp2.getChildren().add(chartDescription); splitter.getItems().addAll(borderPane, sp2); splitter.setDividerPositions(0.70f, 0.30f); return splitter; }
public HtmlPage(String link) { VBox root = new VBox(); Scene scene = new Scene(root); setTitle("FileSend - Page"); final WebView browser = new WebView(); final WebEngine webEngine = browser.getEngine(); try { httpsLoad(webEngine, link); } catch (NoSuchAlgorithmException | KeyManagementException e) { e.printStackTrace(); } root.getChildren().add(browser); VBox.setVgrow(browser, Priority.ALWAYS); getIcons().add(new Image(getClass().getResourceAsStream(".." + File.separator + "images" + File.separator + "logo.png"))); setScene(scene); setMaximized(true); }
public static void wait(WebView view) { Stage stage = new Stage(); WebEngine engine = view.getEngine(); engine.documentProperty().addListener((observable, o, n) -> stage.close()); Scene scene = new Scene(view); stage.initStyle(StageStyle.UNDECORATED); stage.setWidth(1); stage.setHeight(1); stage.setScene(scene); stage.showAndWait(); stage.close(); }
@FXML private void handleValidateButtonAction(ActionEvent event) { String s = StringEscapeUtils.unescapeHtml4(markdownToHtml(currentSourceText.getText())); if (MdConvertController.corrector == null) { MdConvertController.corrector = new Corrector(); } try { String result = MdConvertController.corrector.checkHtmlContent(s); WebEngine webEngine = currentRenderView.getEngine(); webEngine.loadContent("<!doctype html><html lang='fr'><head><meta charset='utf-8'><base href='" + MainApp.class.getResource("assets").toExternalForm() + "' /></head><body>" + result + "</body></html>"); webEngine.setUserStyleSheetLocation(MainApp.class.getResource("assets/static/css/content.css").toExternalForm()); } catch (DOMException e) { log.error(e.getMessage(), e); } }
public void toggleWebView(){ if(webViewBox.isVisible()){ webViewBox.setVisible(false); documentText.setVisible(true); documentTitle.setVisible(true); webViewBox.setPrefWidth(0); webViewBox.setPrefHeight(0); } else{ webViewBox.setVisible(true); documentText.setVisible(false); documentTitle.setVisible(false); webViewBox.setPrefWidth(1500); webViewBox.setPrefHeight(1500); WebEngine engine = webViewBox.getEngine(); System.out.println("Loading " + saveDocument(documentText, documentTitle, false)); engine.loadContent(saveDocument(documentText, documentTitle, false)); } }
public static void init() { Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); stage.initOwner(MineIDE.primaryStage); stage.getIcons().add(new Image(Utils.IMG_DIR + "icon.png")); stage.setTitle("Credits"); StackPane creditsVbox = new StackPane(); WebView browser = new WebView(); WebEngine webEngine = browser.getEngine(); HtmlReader htmlReader = new HtmlReader(); htmlReader.initReading(Utils.HTML_DIR + "credits.html"); webEngine.loadContent(htmlReader.getOutputContent()); creditsVbox.getChildren().add(browser); Scene scene = new Scene(creditsVbox, Gui.width / 1.5, Gui.height / 1.5); scene.setFill(Color.OLDLACE); stage.setScene(scene); stage.setResizable(false); stage.show(); }
public void start(Stage stage){ WebView view = new WebView(); WebEngine e = view.getEngine(); e.loadContent("<div style='height: 50px; background-color: limegreen;'>Narrow div</div>"); view.setMinHeight(MIN_HEIGHT); view.setId(VIEW_ID); VBox box = new VBox(); box.setMaxHeight(MIN_HEIGHT - 10); box.setMinHeight(MIN_HEIGHT - 10); box.setPrefHeight(MIN_HEIGHT - 10); box.getChildren().add(view); final Scene scene = new Scene(box); stage.setTitle(VIEW_ID); stage.setScene(scene); stage.sizeToScene(); stage.show(); System.out.println(view.getHeight()); }
public void start(Stage stage){ WebView view = new WebView(); WebEngine e = view.getEngine(); e.loadContent("<div style='width: 50px; background-color: limegreen;'>Narrow div</div>"); view.setMinWidth(MIN_WIDTH); view.setId(VIEW_ID); HBox box = new HBox(); box.setMaxWidth(MIN_WIDTH - 10); box.setMinWidth(MIN_WIDTH - 10); box.setPrefWidth(MIN_WIDTH - 10); box.getChildren().add(view); final Scene scene = new Scene(box); stage.setTitle(VIEW_ID); stage.setScene(scene); stage.sizeToScene(); stage.show(); System.out.println(view.getWidth()); }
public void start(Stage stage){ WebView view = new WebView(); WebEngine e = view.getEngine(); e.loadContent("<div style='height: 1024px; width: 1024; background-color: limegreen;'>Big div</div>"); view.setMaxSize(MAX_WIDTH, MAX_HEIGHT); view.setId(VIEW_ID); HBox box = new HBox(); box.getChildren().add(view); final Scene scene = new Scene(box); stage.setTitle(VIEW_ID); stage.setScene(scene); stage.sizeToScene(); stage.show(); System.out.println("Width:" + view.getWidth()); System.out.println("Height:" + view.getHeight()); }
public void start(Stage stage){ WebView view = new WebView(); WebEngine e = view.getEngine(); e.loadContent("<div style='height: 30px; width: 30; background-color: limegreen;'>Small div</div>"); view.setMinSize(MIN_WIDTH, MIN_HEIGHT); view.setId(VIEW_ID); VBox box = new VBox(); box.setMaxWidth(MIN_WIDTH - 10); box.setPrefWidth(MIN_WIDTH - 10); box.setMinWidth(MIN_WIDTH - 10); box.setMaxHeight(MIN_HEIGHT - 10); box.setPrefHeight(MIN_HEIGHT - 10); box.setMinHeight(MIN_HEIGHT - 10); box.getChildren().add(view); final Scene scene = new Scene(box); stage.setTitle(VIEW_ID); stage.setScene(scene); stage.sizeToScene(); stage.show(); System.out.println("Width:" + view.getWidth()); System.out.println("Height:" + view.getHeight()); }
public void start(Stage stage){ WebView view = new WebView(); WebEngine e = view.getEngine(); e.loadContent("<div style='width: 1024px; background-color: limegreen;'>Wide div</div>"); view.setMaxWidth(MAX_WIDTH); view.setId(VIEW_ID); VBox box = new VBox(); box.getChildren().add(view); final Scene scene = new Scene(box); stage.setTitle(VIEW_ID); stage.setScene(scene); stage.sizeToScene(); stage.show(); System.out.println(view.getWidth()); }
public void start(Stage stage){ WebView view = new WebView(); WebEngine e = view.getEngine(); e.loadContent("<div style='height: 1024px; background-color: limegreen;'>Tall div</div>"); view.setMaxHeight(MAX_HEIGHT); view.setId(VIEW_ID); HBox box = new HBox(); box.getChildren().add(view); final Scene scene = new Scene(box); stage.setTitle(VIEW_ID); stage.setScene(scene); stage.sizeToScene(); stage.show(); System.out.println(view.getHeight()); }
/** * Test for javafx.scene.web.WebEngine constructor methods. Checks if WebEngine constructor * which accepts the URL string works properly. */ @Test(timeout=10000) public void testConstructor2() { Platform.runLater(new Runnable() { public void run() { String url = null; url = "http://www.yahoo.com"; engine = new WebEngine(url); } }); doWait(new Tester() { public boolean isPassed() { return engine != null; } }); }
@Override public void start(Stage stage) throws Exception { StackPane container = new StackPane(); Scene scene = new Scene(container, SIZE, SIZE); styleInfo = getParameters().getRaw().get(0); WebView view = new WebView(); WebEngine web = view.getEngine(); web.load(CSSLauncher.class.getResource("resources/textSample.html").toExternalForm()); GridPane viewPane = new GridPane(); viewPane.setMaxSize(SIZE, SIZE); viewPane.getChildren().add(view); container.getChildren().addAll(viewPane); stage.setTitle("Launcher"); stage.setScene(scene); stage.sizeToScene(); stage.show(); }
public void start(Stage stage) { StackPane container = new StackPane(); scene = new Scene(container, 800, 800); view = new WebView (); WebEngine engine = view.getEngine(); //using CSSLauncher's test.html engine.load(CSSLauncher.class.getResource("resources/test.html").toExternalForm()); setHandlers(); GridPane viewPane = new GridPane(); viewPane.setMaxSize(size, size); viewPane.getChildren().add(view); container.getChildren().addAll(viewPane, zoomingButton); stage.setTitle("Launcher"); stage.setScene(scene); stage.sizeToScene(); stage.show(); }
public final void initialize(Stage s) { this.stage = s; WebEngine engine = this.webBrowser.getEngine(); String userAgent = engine.getUserAgent(); engine.setUserAgent(userAgent.substring(0, userAgent.indexOf(')')) + "; rv:56.0) Gecko/20100101 Firefox/56.0"); engine.setJavaScriptEnabled(true); engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> { if (newValue.equals(State.SUCCEEDED)) { String location = engine.getLocation(); if (!location.contains("sh.st") && !location.contains("adf.ly") && !location.contains("krothium.com") && !location.contains("about:blank")) { this.webBrowser.getEngine().load("about:blank"); } if (location.contains("about:blank") && !this.toHide.isShowing()) { this.toHide.show(); s.close(); } } }); }
public void loadPage(TextField textField, //ProgressBar progressBar, WebEngine webEngine, WebView webView) { String route = textField.getText(); if (route !=null) if (!route.substring(0, 7).equals("http://")) { route = "http://" + route; textField.setText(route); } System.out.println("Loading route: " + route); //progressBar.progressProperty().bind(webEngine.getLoadWorker().progressProperty()); webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() { @Override public void changed(ObservableValue<? extends State> value, State oldState, State newState) { if(newState == State.SUCCEEDED){ System.out.println("Location loaded + " + webEngine.getLocation()); } } }); webEngine.load(route); }
private static Object executejQuery(final WebEngine engine, String minVersion, String jQueryLocation, String script) { return engine.executeScript( "(function(window, document, version, callback) { " + "var j, d;" + "var loaded = false;" + "if (!(j = window.jQuery) || version > j.fn.jquery || callback(j, loaded)) {" + " var script = document.createElement(\"script\");" + " script.type = \"text/javascript\";" + " script.src = \"" + jQueryLocation + "\";" + " script.onload = script.onreadystatechange = function() {" + " if (!loaded && (!(d = this.readyState) || d == \"loaded\" || d == \"complete\")) {" + " callback((j = window.jQuery).noConflict(1), loaded = true);" + " j(script).remove();" + " }" + " };" + " document.documentElement.childNodes[0].appendChild(script) " + "} " + "})(window, document, \"" + minVersion + "\", function($, jquery_loaded) {" + script + "});"); }
public void showOnlineGame(GameOnline game) { WebEngine webEngine = webView.getEngine(); webEngine.setJavaScriptEnabled(true); URI uri = URI.create(MainApp.webConnector.getUrlFromGame(game)); List<String> cookies = new ArrayList<>(); for(Cookie cookie : MainApp.webConnector.cookies.getCookies()) { cookies.add(cookie.getName() + "=" + cookie.getValue()); } Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>(); headers.put("Set-Cookie", cookies); try { CookieHandler.getDefault().put(uri, headers); } catch (IOException e) { e.printStackTrace(); } webEngine.load(uri.toString()); }
private void loadContent(WebView editor, AceMode aceMode) { AceMode mode = aceMode; WebEngine engine = editor.getEngine(); if (mode == null) mode = AceMode.JAVA; String strMode = "var mode = 'VALUE';\n{{mode-VALUE.js}}" .replaceAll("VALUE", mode.name().toLowerCase()); engine.loadContent(readContent("ace.html", true, strMode)); engine.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> { switch (newState) { case SUCCEEDED: JSObject js = (JSObject) engine.executeScript("window"); gate = new AceJsGate(AceEditor.this, js); if (readyListener != null) readyListener.ready(); break; default: break; } }); }
@Override public final Account authenticate(WebEngine engine) throws AccountException { Account account = null; String url = engine.getLocation(); if (url.contains(OneDriveRestApi.ONEDRIVE_API_REDIRECT_URL)) { if (url.contains("?code=")) { int indexOfCodeString = url.indexOf("?code="); String code = url.substring(indexOfCodeString + "?code=".length()); code = code.substring(0, code.indexOf("&")); account = createAccountFromAuthCode(code); } } return account; }
@Override public final Account authenticate(WebEngine engine) throws AccountException { Account account = null; String code = null; String title = engine.getTitle(); if (title != null) { if (title.contains("Success code")) { try { code = title.split("=")[1].trim(); } catch (Exception ex) { code = null; } } } if (code != null) { account = createAccountFromAuthCode(code); } return account; }
@Override public void start(Stage primaryStage) { final WebView webView = new WebView(); final WebEngine engine = webView.getEngine(); engine.load("http://docs.oracle.com/javafx/2/get_started/animation.htm"); engine.documentProperty().addListener(new ChangeListener<Document>() { @Override public void changed(ObservableValue<? extends Document> prop, Document oldDoc, Document newDoc) { executejQuery( engine, "$(\"a\").click(function(event){" + " event.preventDefault();" + " $(this).hide(\"slow\");" + "});" ); } }); primaryStage.setScene(new Scene(webView)); primaryStage.show(); }
/** * Executes a script which may reference jQuery function on a document. * Checks if the document loaded in a webEngine has a version of jQuery corresponding to * the minimum required version loaded, and, if not, then loads jQuery into the document * from the default JQUERY_LOCATION. * @param engine the webView engine to be used. * @Param jQueryLocation the location of the jQuery script to be executed. * @param minVersion the minimum version of jQuery which needs to be included in the document. * @param script provided javascript script string (which may include use of jQuery functions on the document). * @return the result of the script execution. */ private static Object executejQuery(final WebEngine engine, String minVersion, String jQueryLocation, String script) { return engine.executeScript( "(function(window, document, version, callback) { " + "var j, d;" + "var loaded = false;" + "if (!(j = window.jQuery) || version > j.fn.jquery || callback(j, loaded)) {" + " var script = document.createElement(\"script\");" + " script.type = \"text/javascript\";" + " script.src = \"" + jQueryLocation + "\";" + " script.onload = script.onreadystatechange = function() {" + " if (!loaded && (!(d = this.readyState) || d == \"loaded\" || d == \"complete\")) {" + " callback((j = window.jQuery).noConflict(1), loaded = true);" + " j(script).remove();" + " }" + " };" + " document.documentElement.childNodes[0].appendChild(script) " + "} " + "})(window, document, \"" + minVersion + "\", function($, jquery_loaded) {" + script + "});" ); }
public void setup() { this.dialog = new Dialog(this.root.getScene().getWindow()); this.pluginLoader = new PluginLoader(this.dialog, this.logger); WebEngine webEngine = this.htmlRoot.getEngine(); webEngine.setOnAlert(event -> this.dialog.info(event.getData())); webEngine.load(getClass().getResource("/page/index.html").toString()); this.htmlRoot.setFontSmoothingType(FontSmoothingType.GRAY); this.htmlRoot.setContextMenuEnabled(false); webEngine.getLoadWorker().stateProperty().addListener( (ov, oldState, newState) -> { if (newState == State.SUCCEEDED) this.onLoaded(); }); }
private void initialize() { URL changelog = release.getApplication().getChangelog(); if (changelog != null) { WebEngine engine = changeView.getEngine(); String finalURL = String.format("%s?from=%d&to=%d", changelog, currentReleaseID, release.getId()); engine.load(finalURL); } else { changeView.setVisible(false); changeView.setManaged(false); } Object[] messageArguments = { release.getApplication().getName(), currentVersion, release.getVersion() }; MessageFormat formatter = new MessageFormat(""); formatter.setLocale(resources.getLocale()); if (release.getLicenseVersion() != currentLicenseVersion) { formatter.applyPattern(resources.getString("infotext.paidupgrade")); } else { formatter.applyPattern(resources.getString("infotext.freeupgrade")); } infoLabel.setText(formatter.format(messageArguments)); infoLabel.autosize(); }
public void open(DropboxManager.DropboxAccountLinkListener dropboxAccountLinkListener) throws IOException { final DbxWebAuthNoRedirect webAuth = getDbxWebAuthNoRedirect(); final WebView browser = new WebView(); final WebEngine engine = browser.getEngine(); Stage stage = new Stage(); engine.getLoadWorker().stateProperty().addListener(getListener(dropboxAccountLinkListener, webAuth, engine, stage)); String url = webAuth.start(); LOGGER.debug(url); engine.load(url); StackPane sp = new StackPane(); sp.getChildren().add(browser); stage.initModality(Modality.APPLICATION_MODAL); Scene page2 = new Scene(sp); stage.setScene(page2); stage.show(); }
private ChangeListener<Worker.State> getListener(final DropboxManager.DropboxAccountLinkListener dropboxAccountLinkListener, final DbxWebAuthNoRedirect webAuth, final WebEngine engine, final Stage stage) { return (observable, oldValue, newState) -> { if (newState == Worker.State.SUCCEEDED) { try { final String authCode = (String) engine.executeScript("document.getElementById('auth-code').textContent"); LOGGER.debug("Authorization Code [{}]", authCode); DbxAuthFinish authFinish = webAuth.finish(authCode); String accessToken = authFinish.accessToken; final DbxAuthInfo dbxAuthInfo = new DbxAuthInfo(accessToken, DbxHost.Default); DbxAuthInfo.Writer.writeToFile(dbxAuthInfo, accessTokenFile); DbxClient client = new DbxClient(dropboxConfig, dbxAuthInfo.accessToken, dbxAuthInfo.host); final String displayName = client.getAccountInfo().displayName; LOGGER.info("Linked account [{}]", displayName); stage.close(); dropboxAccountLinkListener.accountLinked(AccountInfoFactory.getAccountInfo(client.getAccountInfo())); } catch (Exception e) { // ignore } } }; }
public void requestLogin() { visualAuthInProgress.set(true); WebEngine webEngine = browser.getEngine(); webEngine.getLoadWorker().stateProperty().addListener((ov, oldValue, newValue) -> { if (newValue == Worker.State.SUCCEEDED) { String location = webEngine.getLocation(); if (location.startsWith(COINBASE_AUTHORIZED_URL_ROOT)) { String code = location.substring(COINBASE_AUTHORIZED_URL_ROOT.length()); apiQueries.submit(() -> { requestTokens(code); Platform.runLater(() -> visualAuthInProgress.set(false)); }); webEngine.setOnStatusChanged(null); } } }); webEngine.load(COINBASE_OAUTH_LOGIN); }
/** * @param javascriptEditor * WebView, in der der Javascript laufen soll. * @param resource * HTML Ressource zur Einbettung des Editors. * @param content * Initialer Inhalt des Editors. */ private void installJavascriptEditorWithInitialContent(final WebView javascriptEditor, final String resource, final String content) { final WebEngine engine = javascriptEditor.getEngine(); engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() { @Override public void changed(final ObservableValue<? extends State> observable, final State oldState, final State newState) { if (newState == State.SUCCEEDED) { engine.getLoadWorker().stateProperty().removeListener(this); statementEditor.setText(content); statementEditor.focus(); } } }); final ResourceLocator locator = new ResourceLocator(); try { javascriptEditor.getEngine() .load(locator.getExternalFormForExplodedResourceInBundle(resource).toExternalForm()); } catch (final Exception e) { installEditorTextArea(); } }
/** * Open a browser view * @param url - the String URL to be opened in the browser view **/ public static void openLink(String url) { TextField urlVal=new TextField(); urlVal.setText(url); urlVal.setPrefHeight(20); urlVal.setEditable(false); urlVal.setId("urlValue"); final WebView browser = new WebView(); browser.setContextMenuEnabled(true); final WebEngine webEngine = browser.getEngine(); VBox br=new VBox(); br.getChildren().addAll(urlVal,browser); Stage browserStage=new Stage(); Scene brScene=new Scene(br); browserStage.setScene(brScene); browserStage.show(); webEngine.load(url); }
@Override public void start(Stage primaryStage) { TextArea textArea = new TextArea(); WebView webView = new WebView(); WebEngine engine = webView.getEngine(); EventStreams.valuesOf(textArea.textProperty()) .successionEnds(Duration.ofMillis(500)) .subscribe(html -> engine.loadContent(html)); SplitPane root = new SplitPane(); root.getItems().addAll(textArea, webView); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); }
public static WebEngine createWebView(FXCanvas canvas) { canvas.setLayout(new FillLayout()); WebView view = new WebView(); // When the WebEngine is initialized a CookieHandler is set, which has // errors reading multi value cookies, therefore set to null again CookieHandler.setDefault(null); Scene scene = new Scene(view); canvas.setScene(scene); WebEngine webkit = view.getEngine(); webkit.setJavaScriptEnabled(true); webkit.setOnAlert(e -> { Logger log = LoggerFactory.getLogger(UI.class); log.error("JavaScript alert: {}", e.getData()); }); return webkit; }
@Override public void init() { setPrefWidth(300); setPrefHeight(300); final WebView webView = new WebView(); Rectangle clipRect = new Rectangle(); clipRect.setWidth(300); clipRect.setHeight(300); clipRect.setArcHeight(20); clipRect.setArcWidth(20); clipRect.setLayoutX(10); clipRect.setLayoutY(10); webView.setClip(clipRect); final WebEngine webEngine = webView.getEngine(); URL url = getClass().getResource("/weather2.html"); System.out.println(url); String fileText = url.toExternalForm(); webEngine.load(fileText); Group grp = new Group(webView); getChildren().add(grp); }