On this page
Class Taskbar
public class Taskbar extends Object
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.appName
system property set to this .desktop file name:Exec=java -Djava.desktop.appName=MyApp.desktop -jar /path/to/myapp.jar
see https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles - Since:
- 9
Nested Class Summary
Modifier and Type | Class | Description |
---|---|---|
static enum |
Taskbar.Feature |
List of provided features.
|
static enum |
Taskbar.State |
Kinds of available window progress states.
|
Method Summary
Modifier and Type | Method | Description |
---|---|---|
Image |
getIconImage() |
Obtains an image of this application's icon.
|
PopupMenu |
getMenu() |
Gets PopupMenu used to add items to this application's icon in system task area.
|
static Taskbar |
getTaskbar() |
Returns the Taskbar instance of the current taskbar context.
|
boolean |
isSupported |
Tests whether a Feature is supported on the current platform.
|
static boolean |
isTaskbarSupported() |
Tests whether this class is supported on the current platform.
|
void |
requestUserAttention |
Requests user attention to this application.
|
void |
requestWindowUserAttention |
Requests user attention to the specified window.
|
void |
setIconBadge |
Affixes a small system-provided badge to this application's icon.
|
void |
setIconImage |
Requests the system to change this application's icon to the provided image .
|
void |
setMenu |
Attaches the contents of the provided PopupMenu to the application icon in the task area.
|
void |
setProgressValue |
Affixes a small system-provided progress bar to this application's icon.
|
void |
setWindowIconBadge |
Affixes a small badge to this application's icon in the task area for the specified window.
|
void |
setWindowProgressState |
Sets a progress state for a specified window.
|
void |
setWindowProgressValue |
Displays a determinate progress bar in the task area for the specified window.
|
Method Details
isSupported
public boolean isSupported(Taskbar.Feature feature)
Feature
is supported on the current platform.
- Parameters:
feature
- the specifiedTaskbar.Feature
- Returns:
- true if the specified feature is supported on the current platform
getTaskbar
public static Taskbar getTaskbar()
Taskbar
instance of the current taskbar context. On some platforms the Taskbar API may not be supported; use the isTaskbarSupported()
method to determine if the current taskbar is supported.
- Returns:
- the Taskbar instance
- Throws:
HeadlessException
- ifGraphicsEnvironment.isHeadless()
returnstrue
UnsupportedOperationException
- if this class is not supported on the current platform- See Also:
isTaskbarSupported
public static boolean isTaskbarSupported()
getTaskbar()
to retrieve an instance.
- Returns:
true
if this class is supported on the current platform;false
otherwise- See Also:
requestUserAttention
public void requestUserAttention(boolean enabled, boolean critical)
enabled
to false. Other platforms may require an additional call requestUserAttention(boolean, boolean)
to dismiss this request with enabled
parameter 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_ATTENTION
feature
requestWindowUserAttention
public void requestWindowUserAttention(Window w)
- 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_WINDOW
feature
setMenu
public void setMenu(PopupMenu menu)
- 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.MENU
feature
getMenu
public PopupMenu getMenu()
- 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.MENU
feature
setIconImage
public void setIconImage(Image image)
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_IMAGE
feature
getIconImage
public Image getIconImage()
- API Note:
-
The returned icon image may not be equal to an image set by
setIconImage(java.awt.Image)
, but should be visually similar. - 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_IMAGE
feature
setIconBadge
public void setIconBadge(String badge)
Feature.ICON_BADGE_TEXT
and Feature.ICON_BADGE_NUMBER
. Passing null
as 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_NUMBER
orTaskbar.Feature.ICON_BADGE_TEXT
feature
setWindowIconBadge
public void setWindowIconBadge(Window w, Image badge)
- 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_WINDOW
feature
setProgressValue
public void setProgressValue(int value)
- 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_VALUE
feature
setWindowProgressValue
public void setWindowProgressValue(Window w, int value)
The visual behavior is platform and
Taskbar.State
dependent. This call cancels the
INDETERMINATE
state 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.OFF
state 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_WINDOW
feature- See Also:
setWindowProgressState
public void setWindowProgressState(Window w, Taskbar.State state)
Each state displays a progress in a platform-dependent way.
Note than switching from
INDETERMINATE
state to any of determinate states may reset value set by setWindowProgressValue
- 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_WINDOW
feature- See Also:
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/java/awt/Taskbar.html