Java Code Examples for javafx.scene.web.WebEngine#loadContent()
The following examples show how to use
javafx.scene.web.WebEngine#loadContent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlWebView.java From Learn-Java-12-Programming with MIT License | 6 votes |
public void start(Stage primaryStage) { try { WebView wv = new WebView(); WebEngine we = wv.getEngine(); String html = "<html><center><h2>Hello, world!</h2></center></html>"; we.loadContent(html, "text/html"); Scene scene = new Scene(wv, 200, 60); primaryStage.setTitle("My HTML page"); primaryStage.setScene(scene); primaryStage.onCloseRequestProperty() .setValue(e -> System.out.println("Bye! See you later!")); primaryStage.show(); } catch (Exception ex){ ex.printStackTrace(); } }
Example 2
Source File: HtmlWebView.java From Learn-Java-12-Programming with MIT License | 6 votes |
public void start8(Stage primaryStage) { try { Text txt = new Text("Below is the embedded HTML:"); WebView wv = new WebView(); WebEngine we = wv.getEngine(); String html = "<html><center><h2>Hello, world!</h2></center></html>"; we.loadContent(html, "text/html"); VBox vb = new VBox(txt, wv); vb.setSpacing(10); vb.setAlignment(Pos.CENTER); vb.setPadding(new Insets(10, 10, 10, 10)); Scene scene = new Scene(vb, 300, 120); primaryStage.setScene(scene); primaryStage.setTitle("JavaFX with embedded HTML"); primaryStage.onCloseRequestProperty() .setValue(e -> System.out.println("Bye! See you later!")); primaryStage.show(); } catch (Exception ex){ ex.printStackTrace(); } }
Example 3
Source File: Blurb.java From marathonv5 with Apache License 2.0 | 6 votes |
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()); }
Example 4
Source File: MdTextController.java From zest-writer with GNU General Public License v3.0 | 6 votes |
@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); } }
Example 5
Source File: WebFrame.java From oim-fx with MIT License | 5 votes |
private void init() { VBox rootVBox = new VBox(); this.setCenter(rootVBox); // this.setBackground("Resources/Images/Wallpaper/1.jpg"); this.setTitle("登录"); this.setWidth(380); this.setHeight(600); this.setRadius(10); StackPane u = new StackPane(); u.setPrefSize(50, 100); // String hString = this.getClass().getResource("/resources/chat/index.html").toString(); File file = new File("Resources/Images/Head/User/90_100.gif"); String fullPath = file.getAbsolutePath(); String htmlText = "<html><body> <lable>666</label>" + "<img src=\"file:/"+fullPath+"\" />" + "</body></html> "; System.out.println(htmlText); WebView webView = new WebView(); webView.setContextMenuEnabled(false); WebEngine we = webView.getEngine(); //we.load(hString); Image logoIamge = new Image(this.getClass().getResource("/resources/login/logo.png").toExternalForm(), true); ImageView logoImageView = new ImageView(); logoImageView.setImage(logoIamge); we.loadContent(htmlText); // Document d = we.getDocument(); // Element root = we.getDocument().getDocumentElement(); // NodeList nl = root.getElementsByTagName("body"); // Node node = nl.item(0); //node.appendChild(node); rootVBox.getChildren().add(u); rootVBox.getChildren().add(webView); }
Example 6
Source File: CreditsStage.java From marathonv5 with Apache License 2.0 | 5 votes |
private void initComponents() { webView.setId("webView"); WebEngine engine = webView.getEngine(); engine.loadContent(getWebViewContent(), "text/html"); VBox.setVgrow(webView, Priority.ALWAYS); okButton.setOnAction((e) -> onOK()); buttonBar.setId("buttonBar"); buttonBar.getButtons().add(okButton); }
Example 7
Source File: WebViewJavaScriptDemo.java From oim-fx with MIT License | 4 votes |
@Override public void start(final Stage primaryStage) { primaryStage.setTitle("Hello World"); WebView webView = new WebView(); // WebPage webPage = null; WebEngine webEngine = webView.getEngine(); // JSObject window = (JSObject) webEngine.executeScript("window"); // window.setMember("app", new JavaApplication()); // webPage = Accessor.getPageFor(webEngine); // webPage.setJavaScriptEnabled(true); // webPage.setEditable(false); // webPage.setContextMenuEnabled(false); // webView.setFocusTraversable(true); StringBuilder html = new StringBuilder(); html.append("<html>"); html.append(" <head>"); html.append(" <title></title>"); html.append(" <meta charset=\"UTF-8\">"); html.append(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"); html.append(" <script type=\"text/javascript\">"); html.append(createLastJavaScript()); html.append(createCheckElementJavaScript()); html.append(createBodyJavaScript()); html.append(" </script>"); html.append(" </head>"); html.append(" <body style=\"word-wrap:break-word;\" >"); html.append(" <a href=\"app.exit();\" onclick=\"app.exit()\">Click here to exit application</a>"); html.append(" <a href=\"javascript:void()\" onclick=\"app.show('hhh')\">hhh</a>"); html.append(" </body>"); html.append("</html>"); webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends State> ov, State oldState, State newState) -> { System.out.println("loadWorker"); if (newState == State.SUCCEEDED) { System.out.println("SUCCEEDED"); } }); webEngine.loadContent(html.toString(), "text/html"); Group root = new Group(); Scene scene = new Scene(root, 1000, 550, Color.LIGHTBLUE); root.getChildren().add(webView); primaryStage.setScene(scene); primaryStage.show(); }
Example 8
Source File: BrowserJavascript.java From mars-sim with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) { WebView webView = new WebView(); WebEngine engine = webView.getEngine(); engine.getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> { if (newState == Worker.State.SUCCEEDED) { addFunctionHandlerToDocument(engine); } }); // Just a demo: in real life can load external HTML resource: engine.loadContent( "<html><head><script>" + "var count = 0 ;" + "function someFunction(x) {" + " count ++ ;" + " document.getElementById(x).innerHTML = 'Count: '+count ;" + "}" + "</script></head>" + "<body>" + " <input type=\"button\" value=\"Click Me\" onclick=\"someFunction('display');\"/>" + " <div id='display'></div>" + "</body>" + "</html>" ); Button registerButton = new Button("Register handler for 'someFunction'"); registerButton.setOnAction(event -> { registerFunction("someFunction", engine); // registering the same function twice will break everything // so don't allow this to happen again: registerButton.setDisable(true); }); HBox controls = new HBox(5, registerButton); controls.setPadding(new Insets(10)); controls.setAlignment(Pos.CENTER); BorderPane root = new BorderPane(webView, null, null, controls, null); Scene scene = new Scene(root, 600, 400); primaryStage.setScene(scene); primaryStage.show(); }