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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Notifies the user of an event by bouncing the application's dock icon.protected static void
Enables the application menu bar for Swing applications.static void
goFullScreen
(JFrame window) Enables fullscreen mode for the specified window.static void
openBrowser
(String url) Deprecated.static boolean
Deprecated.UseSwingUtils.openFile(File)
instead, which provides the same behavior but uses a cross-platform API that also supports other operating systems.static void
revealInFinder
(File file) Reveals the specified file or directory in the Finder.static void
Registers a listener that will be notified every time a menu item in the macOS application menu is clicked.static void
setDockBadge
(String badge) Adds a badge to the application's dock icon with the specified text.static void
setDockIcon
(Image icon) Changes the application's dock icon to the specified image.static void
showNotification
(String title, String message) Sends a notification to the macOS Notification Center.
-
Field Details
-
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
-
enableApplicationMenuBar
protected 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. Usenull
as argument to remove the badge. -
bounceDockIcon
public static void bounceDockIcon()Notifies the user of an event by bouncing the application's dock icon. -
showNotification
Sends a notification to the macOS Notification Center. -
openBrowser
Deprecated.UseSwingUtils.openBrowser(String)
instead, which provides the same behavior but uses a cross-platform API that also supports other operating systems.Opens the default browser with the specified URL. -
openFile
Deprecated.UseSwingUtils.openFile(File)
instead, which provides the same behavior but uses a cross-platform API that also supports other operating systems.Opens the default application for the specified file. Returns true if the file was successfully opened. -
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.
-
SwingUtils.openBrowser(String)
instead, which provides the same behavior but uses a cross-platform API that also supports other operating systems.