← 输入框|chromiumembedded.github.io|刷新

JCEF Documentation

Java Chromium Embedded Framework documentation

View the Project on GitHub chromiumembedded/java-cef

This page describes runtime behavior that applications embedding JCEF should know about. To build JCEF itself, see Branches and Building.

Contents


Embedding in Swing

Call CefApp.startup(args) before initializing AWT/Swing. Configure CEF and create its first client before constructing Swing windows, so native startup does not wait on a window’s accessibility work. Construct and update Swing components on the event dispatch thread (EDT); CEF callbacks may require an explicit SwingUtilities.invokeLater before updating the UI. See the simple sample for startup and shutdown.

For dynamic insertion into an existing JPanel with a BorderLayout, use an already initialized client and update the panel on the EDT:

SwingUtilities.invokeLater(() -> {
    CefBrowser browser = client.createBrowser(initialUrl, false, false);
    panel.add(browser.getUIComponent(), BorderLayout.CENTER);
    panel.revalidate();
    panel.repaint();
});

Browser creation is asynchronous. Supply the initial URL at creation or wait for onAfterCreated before calling methods that require the native browser.

Chromium command-line defaults

JCEF adds these Chromium command-line switches to the browser process at startup, after applying the application’s own switches:

Platform Switch When added
All --disable-gpu-shader-disk-cache CefSettings.cache_path is unset and the application has not set the switch
Linux --ozone-platform=x11 The application has set neither --ozone-platform nor --ozone-platform-hint
macOS --use-core-animation Always
macOS --use-mock-keychain Always
macOS --enable-features=MacOcclusionForceShutoff Always, merged into any existing enable-features list

Overriding defaults

Applications set Chromium switches in either of these places:

Linux: X11 backend

JCEF selects Chromium’s X11 backend (--ozone-platform=x11) by default on Linux. In Wayland sessions this requires XWayland.

Java’s AWT toolkit on Linux is X11-based and runs through XWayland in Wayland sessions. A windowed browser embeds Chromium’s native window as a child of the X11 window of an AWT Canvas. Chromium’s Wayland backend can’t use an X11 window as a parent. Without this default, Chromium selects Wayland in Wayland sessions, and closing a windowed browser never completes.

To choose another backend, set --ozone-platform or --ozone-platform-hint. JCEF then leaves the backend selection to Chromium.

macOS: occlusion detection

JCEF enables Chromium’s MacOcclusionForceShutoff feature by default on macOS, merging it with the application’s existing enable-features list. This disables manual window occlusion detection on macOS 26 and newer to prevent deferred occlusion updates from accessing destroyed Chromium state during shutdown.

JCEF always adds this feature. To opt out, pass --disable-features=MacOcclusionForceShutoff.