Class MacIntegration
Which features are available depend on both the version of macOS and the JRE. In older versions of the JRE these features were accessed through the Apple Java extensions. As of Java 9 these extensions are no longer part of the JRE, with the functionality being added to the AWT desktop API. This class abstracts over these differences, using the appropriate API depending on the used JRE.
Some features were only introduced in later version of macOS, and are not available in earlier versions. Attempting to use a feature that is not available in the current macOS version will have no effect, rather than throwing an exception. This is done to prevent application code from being littered with feature detection checks. The same applies to attempting to use this class on a platform other than macOS, in which case all features will silently fail.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Version -
Method Summary
Modifier and TypeMethodDescriptionstatic voidNotifies the user of an event by bouncing the application's dock icon.static voidEnables the application menu bar for Swing applications.static voidgoFullScreen(JFrame window) Enables fullscreen mode for the specified window.static booleanReturns true if the current platform is (A) a version of macOS, and (B) at least the specified version of macOS.static voidrevealInFinder(File file) Reveals the specified file or directory in the Finder.static voidRegisters a listener that will be notified every time a menu item in the macOS application menu is clicked.static voidsetDockBadge(String badge) Adds a badge to the application's dock icon with the specified text.static voidsetDockIcon(Image icon) Changes the application's dock icon to the specified image.static voidshowNotification(String title, String message) Sends a notification to the macOS Notification Center.
-
Field Details
-
MACOS_TAHOE
-
AQUA_SIZE
- See Also:
-
AQUA_BUTTON
- See Also:
-
AQUA_BUTTON_SEGMENT_POS
- See Also:
-
AQUA_TEXTFIELD
- See Also:
-
AQUA_PROGRESSBAR
- See Also:
-
AQUA_VALUE_SMALL
- See Also:
-
AQUA_VALUE_TEXTURED
- See Also:
-
AQUA_VALUE_SEGMENTED
- See Also:
-
AQUA_VALUE_SEARCH
- See Also:
-
AQUA_VALUE_CIRCULAR
- See Also:
-
AQUA_VALUE_FIRST
- See Also:
-
AQUA_VALUE_MIDDLE
- See Also:
-
AQUA_VALUE_LAST
- See Also:
-
-
Method Details
-
isMacOS
Returns true if the current platform is (A) a version of macOS, and (B) at least the specified version of macOS. The version number inminVersionis assumed to come from theMACOS_Xconstants in this class. -
enableApplicationMenuBar
public static void enableApplicationMenuBar()Enables the application menu bar for Swing applications. By default, Swing will show separate menu bars for each window. This approach is common on Windows and Linux, but macOS applications generally use the same menu bar for the entire application.This method is called by
SwingUtils.initializeSwing(), meaning there is normally no reason for calling this method from application code. -
setApplicationMenuListener
Registers a listener that will be notified every time a menu item in the macOS application menu is clicked. -
setDockIcon
Changes the application's dock icon to the specified image. -
setDockBadge
Adds a badge to the application's dock icon with the specified text. Usenullas argument to remove the badge. -
bounceDockIcon
public static void bounceDockIcon()Notifies the user of an event by bouncing the application's dock icon. -
showNotification
-
revealInFinder
Reveals the specified file or directory in the Finder. If the provided file is not a directory, the Finder will be opened for its parent directory, with the requested file selected. -
goFullScreen
Enables fullscreen mode for the specified window. This has the same effect as the user clicking the green window button.The approach to enable fullscreen mode depends on the Java runtime. If the Apple Java extensions are available, this will trigger Mac OS's "native" fullscreen mode. If the Apple Java extensions are not available, this behavior will be emulated by changing the window dimensions. Mac OS native fullscreen mode cannot be triggered with the standard library, see https://bugs.openjdk.java.net/browse/JDK-8228638 for details.
-