diaphanous-swing is a Java library to apply native translucency/backdrop and window decoration styles to Swing/AWT windows.
Note
At this time only macOs support has been implemented.
Note
Note this library requires running native code, and as such requires the flag --enable-native-access=ALL-UNNAMED to be set.
This project was created under two drivers:
- weisJ/darklaf#351 [Feature Request] Frosted / Blurry background window support (Windows Acrylic / macOs: Vibrant)
- 8375578: Enable translucent window backdrops by beldenfox · Pull Request #2048 · openjdk/jfx
- Windows and Linux aren’t supported (yet).
import io.github.bric3.diaphanous.backdrop.MacosBackdropEffectSpec;
import io.github.bric3.diaphanous.backdrop.MacosBackdropEffectSpec.MacosBackdropMaterial;
import io.github.bric3.diaphanous.backdrop.WindowBackgroundEffectSpec;
import io.github.bric3.diaphanous.backdrop.WindowBackdrop;
import io.github.bric3.diaphanous.decorations.MacosWindowAppearanceSpec;
import io.github.bric3.diaphanous.decorations.MacosWindowDecorationsSpec;
import io.github.bric3.diaphanous.decorations.WindowPresentations;
MacosWindowDecorationsSpec style = MacosWindowDecorationsSpec.builder()
.transparentTitleBar(true)
.fullSizeContentView(true)
.titleVisible(false)
.build();
WindowPresentations.applyDecorations(frame, style);
WindowBackgroundEffectSpec vibrancy = MacosBackdropEffectSpec.builder()
.material(MacosBackdropMaterial.UNDER_WINDOW_BACKGROUND)
.build();
WindowBackdrop.apply(frame, vibrancy);
WindowPresentations.applyAppearance(frame, MacosWindowAppearanceSpec.SYSTEM);Important
To be able to observe bckdrop effects, the swing components MUST be non-opaque
(setOpaque(false)), also the window content pane must forcingly be transparent, see
io.github.bric3.diaphanous.backdrop.RootErasingContentPane and
io.github.bric3.diaphanous.backdrop.ComponentBackdropSupport.
Note
On macOs it has been observed there might be a delay between the backdrop is effectively
changed, this unfortunately shows a white background. At this point I didn't found any
correct fix. However, there is now a workaround that delays the visibility of the window with WindowRevealController.show(frame).
At a high level, this library does two things for Swing windows on macOS:
- It updates
NSWindowstyle/appearance flags (title bar, full-size content, appearance). - It installs/removes an
NSVisualEffectView-based backdrop behind the AWT host view.
Tip
The NSWindow is the real native macOS window behind a JFrame.
On the Swing side, content still needs to cooperate (setOpaque(false) and transparent content pane) so the native backdrop can actually be visible.
flowchart TD
A[Swing code] --> B[WindowPresentations / WindowBackdrop APIs]
B --> C[diaphanous-core facade]
C --> D[Library acquires native OS window pointer]
D --> E[Native macOS operations]
E --> G[NSWindow style updates]
E --> H[Install/update/remove NSVisualEffectView]
H --> I[Backdrop visible through non-opaque Swing content]
What gets changed natively:
- Window decorations:
- Transparent title bar (
setTitlebarAppearsTransparent:) - Full-size content view (
setStyleMask:+NSWindowStyleMaskFullSizeContentView) - Title visibility (
setTitleVisibility:) - Appearance (
setAppearance:)
- Transparent title bar (
- Window backdrop:
NSVisualEffectViewinstall/update/remove- Material/state/alpha configuration (or default install via
WindowBackdrop.install(...))
diaphanous-core: library module.diaphanous-core-macos-native: macOS native bridge (NSViewwrapper + effect view management).demo-swing: sample Swing app using the library.
Decorated mode:
./gradlew :demo-swing:runThe demo is preconfigured with this JVM argument:
--enable-native-access=ALL-UNNAMED
diaphanous-core bundles a simple macOS native library that is loaded it from classpath by default.
For local override/debug, set -Ddiaphanous.macos.nativeLib=/absolute/path/to/libdiaphanous-core-macos-native.dylib.
Robot smoke test:
./gradlew :demo-swing:robotTest- https://github.com/weisJ/darklaf
- https://lukakerr.github.io/swift/nswindow-styles
- https://github.com/macosui/macos_window_utils.dart
- https://github.com/dukke/FXThemes
- openjdk/jfx#2048
Mozilla Public License 2.0 (MPL-2.0). See LICENSE.