java.lang.Object
java.awt.Taskbar
The
Taskbar class allows a Java application to interact with
the system task area (taskbar, Dock, etc.).
There are a variety of interactions depending on the current platform such as displaying progress of some task, appending user-specified menu to the application icon context menu, etc.
- Implementation Note:
- Linux support is currently limited to Unity. However to make these
features work on Unity, the app should be run from a .desktop file with
specified
java.desktop.appNamesystem property set to this .desktop file name:Exec=java -Djava.desktop.appName=MyApp.desktop -jar /path/to/myapp.jarsee https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles - Since:
- 9
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumList of provided features.static enumKinds of available window progress states. -
Method Summary
Modifier and TypeMethodDescriptionObtains an image of this application's icon.getMenu()Gets PopupMenu used to add items to this application's icon in system task area.static TaskbarReturns theTaskbarinstance of the current taskbar context.booleanisSupported(Taskbar.Feature feature) Tests whether aFeatureis supported on the current platform.static booleanTests whether this class is supported on the current platform.voidrequestUserAttention(boolean enabled, boolean critical) Requests user attention to this application.voidRequests user attention to the specified window.voidsetIconBadge(String badge) Affixes a small system-provided badge to this application's icon.voidsetIconImage(Image image) Changes this application's icon to the provided image.voidAttaches the contents of the provided PopupMenu to the application icon in the task area.voidsetProgressValue(int value) Affixes a small system-provided progress bar to this application's icon.voidsetWindowIconBadge(Window w, Image badge) Affixes a small badge to this application's icon in the task area for the specified window.voidsetWindowProgressState(Window w, Taskbar.State state) Sets a progress state for a specified window.voidsetWindowProgressValue(Window w, int value) Displays a determinate progress bar in the task area for the specified window.
-
Method Details
-
isSupported
Tests whether aFeatureis supported on the current platform.- Parameters:
feature- the specifiedTaskbar.Feature- Returns:
- true if the specified feature is supported on the current platform
-
getTaskbar
Returns theTaskbarinstance of the current taskbar context. On some platforms the Taskbar API may not be supported; use theisTaskbarSupported()method to determine if the current taskbar is supported.- Returns:
- the Taskbar instance
- Throws:
HeadlessException- ifGraphicsEnvironment.isHeadless()returnstrueUnsupportedOperationException- if this class is not supported on the current platform- See Also:
-
isTaskbarSupported
public static boolean isTaskbarSupported()Tests whether this class is supported on the current platform. If it's supported, usegetTaskbar()to retrieve an instance.- Returns:
trueif this class is supported on the current platform;falseotherwise- See Also:
-
requestUserAttention
public void requestUserAttention(boolean enabled, boolean critical) Requests user attention to this application. Depending on the platform, this may be visually indicated by a bouncing or flashing icon in the task area. It may have no effect on an already active application. On some platforms (e.g. Mac OS) this effect may disappear upon app activation and cannot be dismissed by settingenabledto false. Other platforms may require an additional callrequestUserAttention(boolean, boolean)to dismiss this request withenabledparameter set to false.- Parameters:
enabled- disables this request if falsecritical- if this is an important request- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.USER_ATTENTIONfeature
-
requestWindowUserAttention
Requests user attention to the specified window. Has no effect if a window representation is not displayable in the task area. Whether it is displayable is dependent on all of window type, platform, and implementation.- Parameters:
w- window- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.USER_ATTENTION_WINDOWfeature
-
setMenu
Attaches the contents of the provided PopupMenu to the application icon in the task area.- Parameters:
menu- the PopupMenu to attach to this application- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.MENUfeature
-
getMenu
Gets PopupMenu used to add items to this application's icon in system task area.- Returns:
- the PopupMenu
- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.MENUfeature
-
setIconImage
Changes this application's icon to the provided image.- Parameters:
image- to change- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.ICON_IMAGEfeature
-
getIconImage
Obtains an image of this application's icon.- Returns:
- an image of this application's icon
- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.ICON_IMAGEfeature
-
setIconBadge
Affixes a small system-provided badge to this application's icon. Usually a number. Some platforms do not support string values and accept only integer values. In this case, pass an integer represented as a string as parameter. This can be tested byFeature.ICON_BADGE_TEXTandFeature.ICON_BADGE_NUMBER. Passingnullas parameter hides the badge.- Parameters:
badge- label to affix to the icon- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.ICON_BADGE_NUMBERorTaskbar.Feature.ICON_BADGE_TEXTfeature
-
setWindowIconBadge
Affixes a small badge to this application's icon in the task area for the specified window. It may be disabled by system settings. Has no effect if a window representation is not displayable in the task area. Whether it is displayable is dependent on all of window type, platform, and implementation.- Parameters:
w- window to updatebadge- image to affix to the icon- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.ICON_BADGE_IMAGE_WINDOWfeature
-
setProgressValue
public void setProgressValue(int value) Affixes a small system-provided progress bar to this application's icon.- Parameters:
value- from 0 to 100, other to disable progress indication- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.PROGRESS_VALUEfeature
-
setWindowProgressValue
Displays a determinate progress bar in the task area for the specified window. Has no effect if a window representation is not displayable in the task area. Whether it is displayable is dependent on all of window type, platform, and implementation.
The visual behavior is platform andTaskbar.Statedependent.
This call cancels theINDETERMINATEstate of the window.
Note that when multiple windows is grouped in the task area the behavior is platform specific.- Parameters:
w- window to updatevalue- from 0 to 100, other to switch toTaskbar.State.OFFstate and disable progress indication- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.PROGRESS_VALUE_WINDOWfeature- See Also:
-
setWindowProgressState
Sets a progress state for a specified window. Has no effect if a window representation is not displayable in the task area. Whether it is displayable is dependent on all of window type, platform, and implementation.
Each state displays a progress in a platform-dependent way.
Note than switching fromINDETERMINATEstate to any of determinate states may reset value set bysetWindowProgressValue- Parameters:
w- windowstate- to change to- Throws:
SecurityException- if a security manager exists and it denies theRuntimePermission("canProcessApplicationEvents")permission.UnsupportedOperationException- if the current platform does not support theTaskbar.Feature.PROGRESS_STATE_WINDOWfeature- See Also:
-