JavaFX Tutorial 27 - WebView Java GUI

Опубликовано: 21 Февраль 2025
на канале: Code Amir
1,165
8

JavaFX Tutorial 27 WebView
Source Code :
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX Tutorial WebView ");
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
// webEngine.load("http://facebook.com");

String content = "Code Amir / JavaFX tutorial";
webEngine.loadContent(content, "text/html");
webEngine.executeScript("Function()");

VBox vBox = new VBox(webView);
Scene scene = new Scene(vBox, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
}

Libraries Importing :
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

The JavaFX WebView (javafx.scene.web.WebView) component is capable of showing web pages (HTML, CSS, SVG, JavaScript) inside a JavaFX application. As such, the JavaFX WebView is a mini browser. The WebView component is very handy when you need to show documentation (e.g. Help texts), news, blog posts or other content which needs to be downloaded from a web server at runtime.

The JavaFX WebView uses the WebKit open source browser engine internally to render the web pages.