Both JxBrowser and JavaFX WebView allow you to bring web technologies in your cross-platform Java desktop application to get the best of both worlds: the ubiquity of the web platform and the power of the Java platform.
Before choosing JxBrowser our clients sometimes ask us about the difference between JxBrowser and JavaFX WebView. In this article we will compare these solutions in terms of their architecture, rendering, support of the latest web standards including HTML5, CSS3, JavaScript, and more.
In a nutshell
If you develop your software using JavaFX and you need to display a simple web page with no need to use HTML5 features or advanced web browser functionality, JavaFX WebView will work well for the case.
For time-sensitive commercial software development on JavaFX, Swing, or SWT, where stability, timely support and effective communication are a must, JxBrowser is the most reliable choice.
Installation
JavaFX WebView was introduced in JavaFX 2.0 that became a part of JDK 8 in 2014. If you use Java 8, then you don’t need to do anything special to start using JavaFX WebView. With JDK 11 and higher JavaFX is no longer bundled, so to develop using JavaFX or higher you must download it separately.
JxBrowser is a third-party library that you need to add to your project as a dependency. You can simply download and add it to your application classpath, or quickly add it to your Gradle or Maven project.
Sending…
Sorry, the sending was interrupted
Please try again. If the issue persists, contact us at info@teamdev.com.
Your personal JxBrowser trial key and quick start guide will arrive in your Email Inbox in a few minutes.
Engine
JavaFX WebView uses WebKit internally. JxBrowser uses a fully-functional Chromium under the hood. Both solutions include all the necessary engine binaries and do not require the end users to install Chromium or Safari.
Rendering
WebKit does not render web pages, so JavaFX developers had to implement a separate lightweight (off-screen) renderer. JavaFX 21 WebView renders web pages well, so there won’t be any visible differences compared with Safari, Mozilla Firefox, or Google Chrome.
In JxBrowser the web pages are rendered by Chromium using GPU. So they look exactly as in Google Chrome. JxBrowser supports two rendering modes: off-screen and hardware accelerated.
Architecture
JavaFX initializes and runs WebKit in your Java process. The advantage of this approach is that JavaFX allows you to create and display WebView very quickly compared to JxBrowser, where an external Chromium process must be launched first. However, to obtain such a speed WebKit allocates and uses the memory and CPU of your Java process. Some modern web pages might allocate more than 1GB of RAM. The more WebView instances you create and load web pages, the more RAM of your Java application will be taken.
JxBrowser runs Chromium in a separate native process and communicates with it via the Inter-Process Communication (IPC) bridge. With this solution, Chromium does not affect the memory usage of your Java application. Moreover, JxBrowser supports Chromium multi-process architecture. If a web page or JavaScript crashes for some reason, Chromium will continue working and you can even restore the crashed web page.
Security
WebKit is written using C++. To call WebKit functionality, JavaFX WebView uses JNI. Since WebKit is running inside JVM, any error or unexpected behavior might cause a JVM crash and terminate your Java application unexpectedly. The end user’s data might be lost or corrupted.
In case of an error in Chromium, your Java program will continue running. JxBrowser even provides an API to inform you about unexpected Chromium termination or crash in a Chromium process, so you can re-initialize and restore a user session for a better user experience.
Web Standards
If you load https://html5test.teamdev.com/ in JavaFX 21 WebView and JxBrowser 8.1.0 (Chromium 130) you will get the following results:
Different JavaFX versions support different web standards. For example, JavaFX 8 does not play video on YouTube at all:
And renders Google with some artifacts:
JavaFX 21 works well for the same tasks:
WebGL is not supported by JavaFX.
Google Maps are not displayed properly even in JavaFX 21:
Supported UI Toolkits
JavaFX WebView can be seamlessly used for JavaFX applications. If you develop your app using Java Swing or SWT, then you can embed JavaFX WebView via JFXPanel and FXCanvas.
JxBrowser supports all Java UI toolkits including JavaFX, Swing, and SWT. It provides the following components for embedding:
com.teamdev.jxbrowser.view.swing.BrowserView
com.teamdev.jxbrowser.view.javafx.BrowserView
com.teamdev.jxbrowser.view.swt.BrowserView
Embedding
The efforts required to write a simple JavaFX app with an address bar and web view that renders the currently loaded web page are pretty similar.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public final class Main extends Application {
@Override
public void start(Stage primaryStage) {
WebView view = new WebView();
WebEngine engine = view.getEngine();
BorderPane root = new BorderPane(view);
TextField addressBar = new TextField("https://google.com");
addressBar.setOnAction(event ->
engine.load(addressBar.getText()));
root.setTop(addressBar);
// Update address bar with URL of the loaded web page.
engine.locationProperty().addListener((observable, oldValue, newValue) ->
addressBar.setText(newValue));
primaryStage.setTitle("JavaFX WebView");
primaryStage.setScene(new Scene(root, 1000, 600));
primaryStage.show();
engine.load(addressBar.getText());
}
}
import static com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED;
import com.teamdev.jxbrowser.browser.Browser;
import com.teamdev.jxbrowser.engine.Engine;
import com.teamdev.jxbrowser.navigation.event.NavigationFinished;
import com.teamdev.jxbrowser.view.javafx.BrowserView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public final class SmokeTest extends Application {
@Override
public void start(Stage primaryStage) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
BrowserView view = BrowserView.newInstance(browser);
BorderPane root = new BorderPane(view);
TextField addressBar = new TextField("https://google.com");
addressBar.setOnAction(event ->
browser.navigation().loadUrl(addressBar.getText()));
root.setTop(addressBar);
// Update address bar with URL of the loaded web page.
browser.navigation().on(NavigationFinished.class, event -> {
if (event.isInMainFrame()) {
addressBar.setText(event.url());
}
});
primaryStage.setTitle("JxBrowser");
primaryStage.setScene(new Scene(root, 1000, 600));
primaryStage.show();
browser.navigation().loadUrl(addressBar.getText());
// Close the engine when stage is about to close.
primaryStage.setOnCloseRequest(event -> engine.close());
}
}
API and features
JavaFX WebView API: ~1 package, ~10 classes & interfaces. JavaFX WebView is a simple web browser control. There were no goals to provide the functionality of a fully-functional web browser such as network, SSL, authentication, cookies, DevTools, plugins, PDF Viewer, etc.
The API provides the basic web browser functionality that allows loading a web page, getting various load events, accessing and modifying DOM, executing JavaScript, calling Java from JavaScript by injecting Java objects into JavaScript, handling popups, and displaying JavaScript dialogs such as alert, confirm, prompt.
JxBrowser API: ~60 packages, ~580 classes & interfaces. JxBrowser wraps and uses a fully-functional web browser app under the hood.
The API provides access to hundreds of the Chromium features such as managing profiles including incognito, plugins, proxy, cookies, spell checking, downloads, permissions, authentication (proxy, basic, digest, NTLM, SSL client certificates, SuisseID, U2F, Integrated Windows Authentication and Kerberos), passwords, zoom, printing, DevTools, network, custom protocols and more.
Support and updates
JavaFX is an open source project. If you see a bug or there is a missing feature, you can contribute. JavaFX follows OpenJDKs 6-months release cycle. A new version is released every 6 months. It is still unknown how often the WebKit engine is upgraded to the latest stable version that supports the latest web standards and includes the fixes of the reported security vulnerabilities.
JxBrowser is a commercial product designed and created for commercial companies that have high requirements for the quality and support of integrated third-party solutions, and develop software using Java technology. JxBrowser has been developed and supported by TeamDev since 2007.
All the clients with an active Standard Support subscription can use all new JxBrowser versions for free and receive technical support from JxBrowser engineers directly. If you see a bug or there is a missing feature, we will apply the fix, implement the required feature, and provide you with a new version of the library within a reasonable amount of time.
A new version of JxBrowser is released almost every month. We upgrade Chromium to the latest stable version (with the latest security patches and fixed vulnerabilities) within 3–4 weeks after its official release.