macOS
Cocoa · WKWebViewFull native embedding on 10.13+. Hardware-accelerated WKWebView with Swing widgets layered around it.
Cross-platform — native WebKit / WebView2 rendering on macOS, Linux, and Windows. Native libs bundled in the jar — one Maven dependency, zero install steps.
Drop this into your pom.xml. The jar bundles the
native libraries for macOS, Linux, and Windows.
<dependency>
<groupId>ca.weblite</groupId>
<artifactId>webview</artifactId>
<version>1.0.7</version>
</dependency>
implementation 'ca.weblite:webview:1.0.7'
One factory call. WebViewComponent.create() returns
the right native WebView for the current platform.
import ca.weblite.webview.swing.WebViewComponent;
import javax.swing.*;
import java.awt.*;
public class Demo {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
WebViewComponent wv = WebViewComponent.create();
wv.setUrl("https://example.com");
wv.setPreferredSize(new Dimension(900, 600));
JFrame frame = new JFrame("WebView Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(wv, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
});
}
}
That's it — mvn package && java -jar
target/your-app.jar and you have a native WebView running
inside Swing.
WebViewComponent.create() returns a fully-functional
native WebView on each supported platform — rendering, mouse,
keyboard, scrolling, resize, and tab visibility all work out of the
box.
Full native embedding on 10.13+. Hardware-accelerated WKWebView with Swing widgets layered around it.
Full rendering, mouse, and keyboard via WebKitGTK. Requires
libwebkit2gtk-4.1 (or 4.0) and an X11
display.
Full native embedding on Windows 11 and recent Windows 10 via the Microsoft Edge WebView2 Runtime.
Three methods cover the whole interop surface — fire-and-forget, round-trip-with-result, and page-initiated callbacks.
eval(String js)Fire-and-forget. Use for side effects.
wv.eval("document.title = 'Hi';");
evalAsync(String js)Returns a CompletableFuture<String> resolved with the
JSON-stringified result. Continuations land on the EDT.
wv.evalAsync("return [window.scrollX, window.scrollY];")
.thenAccept(json -> System.out.println(json));
addJavascriptCallback(...)Exposes a Java callback at window.<name>(arg) for the page to invoke.
wv.addJavascriptCallback("notify", arg -> {
System.out.println("page said: " + arg);
});
window.alert, confirm, prompt,
and <input type="file"> are all routed through
WebViewDialogHandler. The default handler shows
Swing dialogs; install your own to customise or suppress them.
wv.setDialogHandler(new WebViewDialogHandler() {
@Override public boolean confirmOpened(WebViewConfirmEvent e) {
return JOptionPane.showConfirmDialog(
frame, e.message(), "Confirm",
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION;
}
});
Pass null to install the headless-test drop handler
(alert no-op, confirm → false, prompt →
null, file picker → empty list). Pass
WebViewDialogHandler.DEFAULT to reset to the Swing
default.
Each demo has launcher scripts at the project root
(run-mac-*.sh, run-linux-*.sh,
run-windows-*.bat).
WebViews embedded alongside Swing widgets (JComboBox, tabs) interacting around them.
Primitive / object / Promise results, exceptions surfacing as JavaScriptEvalException, EDT continuations.
Default Swing, custom programmatic answers, and headless drop mode — for all four dialog kinds.
Right-click target descriptors: link / image / editable / selection, and setDefaultContextMenuEnabled.
The non-Swing WebView primitive, driven from a console app.
git clone https://github.com/webliteca/swingwebview
cd swingwebview
mvn -DskipTests package
Produces target/webview-1.0-SNAPSHOT.jar. Targets Java 8
bytecode; works on JDK 8 and any newer LTS. Native libs are
rebuilt by build-mac.sh /
build-linux.sh / build-windows.sh;
the cross-platform fat jar is produced by the GitHub Actions
release workflow.