Skip to content

Instantly share code, notes, and snippets.

@wiverson
Last active April 24, 2024 19:37
Show Gist options
  • Save wiverson/5308a91fcb41a59a0b802e7953891ed9 to your computer and use it in GitHub Desktop.
Save wiverson/5308a91fcb41a59a0b802e7953891ed9 to your computer and use it in GitHub Desktop.
HOWTO make a Java Swing app look great on macOS

All of this has been confirmed to work on macOS Big Sur (11.2.3) and JDK 16.

macOS Menu Bar

To put the menu bar at the top of the screen, use the following

System.setProperty("apple.laf.useScreenMenuBar", "true");

// Use this method to set the menu bar.
jFrame.setJMenuBar(jMenuBar);

macOS Window Decoration

Add this library to your build...

https://github.com/0x4a616e/NSMenuFX

...and then call...

MenuToolkit.toolkit().setAppearanceMode(AppearanceMode.AUTO);

...before anything else.

Modern Light & Dark Look & Feel

To make Swing look modern, check out this (free, open source) Swing look & feel:

https://www.formdev.com/flatlaf/

Bonus: support for a wide variety of themes, including several based on IntelliJ - perfect if you happen to be working on a developer tool and want to provide a switchable theme experience.

Desktop Integration

You probably want to implement handlers for many of the integration APIs in java.awt.Desktop for basic application integration.

A LOT of other integration is also available by browsing through the list of material available around the java.desktop module.

Installer & App Packaging

An example of building installers with nice, small JVMs can be found at:

https://github.com/wiverson/desktop-spring-boot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment