Documentation
Getting started with JxBrowser
This guide shows how to start working with JxBrowser in your Gradle or Maven project as quickly as possible.
Prerequisites
Please make sure your system meets the software and hardware requirements.
Choose your project build tool
Please add the JxBrowser Gradle plugin to your build script file build.gradle(.kts)
and configure the JxBrowser dependency as shown below:
plugins {
id("com.teamdev.jxbrowser") version "1.2.1"
}
jxbrowser {
version = "8.0.0"
}
dependencies {
implementation(jxbrowser.crossPlatform)
}
plugins {
id 'com.teamdev.jxbrowser' version '1.2.1'
}
jxbrowser {
version '8.0.0'
}
dependencies {
implementation jxbrowser.crossPlatform
}
Please add JxBrowser to your pom.xml
as shown below:
<repositories> <repository> <id>com.teamdev</id> <url>https://europe-maven.pkg.dev/jxbrowser/releases</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.teamdev.jxbrowser</groupId> <artifactId>jxbrowser-cross-platform</artifactId> <version>8.0.0</version> <type>pom</type> </dependency> </dependencies>
Choose the software you are/will be working on
The following simple example demonstrates how to load a web page, wait until it's loaded completely, and print its HTML:
// Initialize Chromium.
var options = EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.licenseKey("your license key")
.build();
var engine = Engine.newInstance(options);
// Create a Browser instance.
var browser = engine.newBrowser();
// Load a web page and wait until it is loaded completely.
browser.navigation().loadUrlAndWait("https://html5test.teamdev.com/");
// Print HTML of the loaded web page.
browser.mainFrame().ifPresent(frame -> System.out.println(frame.html()));
// Shutdown Chromium and release allocated resources.
engine.close();
// Initialize Chromium.
val engine = Engine(HARDWARE_ACCELERATED) {
license = JxBrowserLicense("your license key")
}
// Create a Browser instance.
val browser = engine.newBrowser()
// Load a web page and wait until it is loaded completely.
browser.navigation().loadUrlAndWait("https://html5test.teamdev.com/")
// Print HTML of the loaded web page.
browser.mainFrame().ifPresent { frame -> println(frame.html()) }
// Shutdown Chromium and release allocated resources.
engine.close()
See full example on GitHub.
Choose your Java UI toolkit
Please add the JxBrowser Swing library to your build.gradle
:
dependencies {
implementation(jxbrowser.swing)
}
dependencies {
implementation jxbrowser.swing
}
Please add the JxBrowser Swing library to your pom.xml
:
<dependency> <groupId>com.teamdev.jxbrowser</groupId> <artifactId>jxbrowser-swing</artifactId> <version>8.0.0</version> </dependency>
Now you can embed JxBrowser Swing component into your Java Swing application as shown below:
// Initialize Chromium.
var options = EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.licenseKey("your license key")
.build();
var engine = Engine.newInstance(options);
// Create a Browser instance.
var browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
var frame = new JFrame("JxBrowser AWT/Swing");
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Shutdown Chromium and release allocated resources.
engine.close();
}
});
// Create and embed Swing BrowserView component to display web content.
frame.add(BrowserView.newInstance(browser));
frame.setSize(1280, 800);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
// Load the required web page.
browser.navigation().loadUrl("https://html5test.teamdev.com/");
});
// Initialize Chromium.
val engine = Engine(HARDWARE_ACCELERATED) {
license = JxBrowserLicense("your license key")
}
// Create a Browser instance.
val browser = engine.newBrowser()
SwingUtilities.invokeLater {
JFrame("JxBrowser AWT/Swing").apply {
// Shutdown Chromium and release allocated resources when the frame closes.
addWindowListener(object : WindowAdapter() {
override fun windowClosing(e: WindowEvent) {
engine.close()
}
})
// Create and embed Swing BrowserView component to display web content.
add(BrowserView.newInstance(browser))
setSize(1280, 800)
setLocationRelativeTo(null)
isVisible = true
}
// Load the required web page.
browser.navigation().loadUrl("https://html5test.teamdev.com/")
}
You should see the following output:
Please feel free to download and use an already configured project with Swing GUI from GitHub.
Please add the JxBrowser JavaFX library to your build.gradle
:
dependencies {
implementation(jxbrowser.javafx)
}
dependencies {
implementation jxbrowser.javafx
}
Please add the JxBrowser JavaFX library to your pom.xml
:
<dependency> <groupId>com.teamdev.jxbrowser</groupId> <artifactId>jxbrowser-javafx</artifactId> <version>8.0.0</version> </dependency>
Now you can embed JxBrowser JavaFX control into your JavaFX application as shown below:
// Initialize Chromium.
var options = EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.licenseKey("your license key")
.build();
var engine = Engine.newInstance(options);
// Create a Browser instance.
var browser = engine.newBrowser();
// Load the required web page.
browser.navigation().loadUrl("https://html5test.teamdev.com");
// Create and embed JavaFX BrowserView component to display web content.
var view = BrowserView.newInstance(browser);
var scene = new Scene(new BorderPane(view), 1280, 800);
primaryStage.setTitle("JxBrowser JavaFX");
primaryStage.setScene(scene);
primaryStage.show();
// Shutdown Chromium and release allocated resources.
primaryStage.setOnCloseRequest(event -> engine.close());
// Initialize Chromium.
val engine = Engine(HARDWARE_ACCELERATED) {
license = JxBrowserLicense("your license key")
}
// Create a Browser instance.
val browser = engine.newBrowser()
// Load the required web page.
browser.navigation().loadUrl("https://html5test.teamdev.com")
// Create and embed JavaFX BrowserView component to display web content.
val view = BrowserView.newInstance(browser)
val scene = Scene(BorderPane(view), 1280.0, 800.0)
primaryStage.title = "JxBrowser JavaFX"
primaryStage.scene = scene
primaryStage.show()
// Shutdown Chromium and release allocated resources.
primaryStage.setOnCloseRequest { engine.close() }
You should see the following output:
Please feel free to download and use an already configured project with JavaFX GUI from GitHub.
Please add the JxBrowser SWT library to your build.gradle
:
dependencies {
implementation(jxbrowser.swt)
}
dependencies {
implementation jxbrowser.swt
}
Please add the JxBrowser SWT library to your pom.xml
:
<dependency> <groupId>com.teamdev.jxbrowser</groupId> <artifactId>jxbrowser-swt</artifactId> <version>8.0.0</version> </dependency>
Now you can embed JxBrowser SWT widget into your Java SWT application as shown below:
// Initialize Chromium.
var options = EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.licenseKey("your license key")
.build();
var engine = Engine.newInstance(options);
// Create a Browser instance.
var browser = engine.newBrowser();
// Load the required web page.
browser.navigation().loadUrl("https://html5test.teamdev.com");
var display = new Display();
var shell = new Shell(display);
shell.setText("JxBrowser SWT");
shell.setLayout(new FillLayout());
// Create and embed SWT BrowserView widget to display web content.
var view = BrowserView.newInstance(shell, browser);
view.setSize(1280, 800);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
// Shutdown Chromium and release allocated resources.
engine.close();
display.dispose();
// Initialize Chromium.
val engine = Engine(HARDWARE_ACCELERATED) {
license = JxBrowserLicense("your license key")
}
// Create a Browser instance.
val browser = engine.newBrowser()
// Load the required web page.
browser.navigation().loadUrl("https://html5test.teamdev.com")
val display = Display()
val shell = Shell(display)
shell.text = "JxBrowser SWT"
shell.layout = FillLayout()
// Create and embed SWT BrowserView widget to display web content.
val view = BrowserView.newInstance(shell, browser)
view.setSize(1280, 800)
shell.pack()
shell.open()
while (!shell.isDisposed) {
if (!display.readAndDispatch()) {
display.sleep()
}
}
// Shutdown Chromium and release allocated resources.
engine.close()
display.dispose()
You should see the following output:
Please feel free to download and use an already configured project with SWT GUI from GitHub.
Add the JxBrowser Compose library to your build.gradle
:
dependencies {
implementation(jxbrowser.compose)
}
dependencies {
implementation jxbrowser.compose
}
Add the JxBrowser Compose library to your pom.xml
:
Now you can embed JxBrowser Compose widget into your Java Compose Desktop application as shown below:
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.unit.dp import androidx.compose.ui.window.WindowState import androidx.compose.ui.window.singleWindowApplication import com.teamdev.jxbrowser.dsl.Engine import com.teamdev.jxbrowser.dsl.browser.navigation import com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN import com.teamdev.jxbrowser.view.compose.BrowserView fun main() = singleWindowApplication( title = "Compose Desktop BrowserView", state = WindowState(width = 1280.dp, height = 800.dp), ) { val engine = remember { Engine(OFF_SCREEN) } val browser = remember { engine.newBrowser() } BrowserView(browser) LaunchedEffect(Unit) { browser.navigation.loadUrl("https://html5test.teamdev.com") } }
You should see the following output:
Feel free to download and use an already configured project with Compose Desktop GUI from GitHub.
What's next
- Read how JxBrowser works in the architecture and design guides.
- Check out our guides to learn more about all JxBrowser features.
- Explore the JxBrowser API in reference documentation.