Desktop class allows interact with various desktop capabilities.
Supported operations include:
mailto URI; This class provides methods corresponding to these
operations. The methods look for the associated application
registered on the current platform, and launch it to handle a URI
or file. If there is no associated application or the associated
application fails to be launched, an exception is thrown.
Please see Desktop. for the full list of supported operations
and capabilities.
An application is registered to a URI or file type. The mechanism of registering, accessing, and launching the associated application is platform-dependent.
Each operation is an action type represented by the Desktop. class.
Note
when some action is invoked and the associated application is executed, it will be executed on the same system as the one on which the Java application was launched.
Action
| Modifier and Type | Class and Description |
|---|---|
| public static enum | Desktop.
Represents an action type. |
| Modifier and Type | Field and Description |
|---|---|
| private static Desktop | |
| private DesktopPeer |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | addAppEventListener(final SystemEventListener
listener listener)Adds sub-types of |
| public void | |
| public void | browseFileDirectory(File
the file file)Opens a folder containing the |
| private void | checkActionSupport(Desktop.
the action type in question actionTypeChecks if the action type is supported. |
| private static void | |
| public void | |
| public void | |
| public void | |
| public static synchronized Desktop | Returns: the Desktop instanceReturns the |
| public static boolean | Returns: true if this class is supported on the
current platform; false otherwiseTests whether this class is supported on the current platform. |
| public boolean | Returns: true if the specified action is supported on
the current platform; false otherwisethe specified actionActionTests whether an action is supported on the current platform. |
| public void | |
| public void | |
| public boolean | Returns: returns true if successfully moved the file to the trash.the file file)Moves the specified file to the trash. |
| public void | |
| public void | |
| public void | |
| public void | removeAppEventListener(final SystemEventListener
listener listener)Removes sub-types of |
| public void | requestForeground(final boolean
if all windows of this application should be moved to
the foreground, or only the foremost one allWindows)Requests this application to move to the foreground. |
| public void | setAboutHandler(final AboutHandler
the handler to respond to the
aboutHandler)java. messageInstalls a handler to show a custom About window for your application. |
| public void | setDefaultMenuBar(final JMenuBar
to use when no other frames are active menuBar)Sets the default menu bar to use when there are no active frames. |
| public void | setOpenFileHandler(final OpenFilesHandler
handler openFileHandler)Installs the handler which is notified when the application is asked to open a list of files. |
| public void | setOpenURIHandler(final OpenURIHandler
handler openURIHandler)Installs the handler which is notified when the application is asked to open a URL. |
| public void | setPreferencesHandler(final PreferencesHandler
the handler to respond to the
preferencesHandler)PreferencesHandler#handlePreferences(PreferencesEvent)Installs a handler to show a custom Preferences window for your application. |
| public void | setPrintFileHandler(final PrintFilesHandler
handler printFileHandler)Installs the handler which is notified when the application is asked to print a list of files. |
| public void | setQuitHandler(final QuitHandler
the handler that is called when the application is
asked to quit quitHandler)Installs the handler which determines if the application should quit. |
| public void | setQuitStrategy(final QuitStrategy
the way this application should be shutdown strategy)Sets the default strategy used to quit this application. |
| desktop | back to summary |
|---|---|
| private static Desktop desktop | |
| peer | back to summary |
|---|---|
| private DesktopPeer peer | |
| Desktop | back to summary |
|---|---|
| private Desktop() Suppresses default constructor for noninstantiability. | |
| addAppEventListener | back to summary |
|---|---|
| public void addAppEventListener(final SystemEventListener listener) Adds sub-types of | |
| browse | back to summary |
|---|---|
| public void browse(URI uri) throws IOException Launches the default browser to display a
| |
| browseFileDirectory | back to summary |
|---|---|
| public void browseFileDirectory(File file) Opens a folder containing the
| |
| checkActionSupport | back to summary |
|---|---|
| private void checkActionSupport(Desktop. Checks if the action type is supported.
| |
| checkFileValidation | back to summary |
|---|---|
| private static void checkFileValidation(File file) Checks if the file is a valid file and readable.
| |
| disableSuddenTermination | back to summary |
|---|---|
| public void disableSuddenTermination() Prevents this application from being suddenly terminated. Call this method to indicate that your application has unsaved state, and may not be terminated without notification.
| |
| edit | back to summary |
|---|---|
| public void edit(File file) throws IOException Launches the associated editor application and opens a file for editing.
| |
| enableSuddenTermination | back to summary |
|---|---|
| public void enableSuddenTermination() Enables this application to be suddenly terminated. Call this method to indicate your application's state is saved, and requires no notification to be terminated. Letting your application remain terminatable improves the user experience by avoiding re-paging in your application when it's asked to quit. Note: enabling sudden termination will allow your application to be quit without notifying your QuitHandler, or running any shutdown hooks. E.g. user-initiated Cmd-Q, logout, restart, or shutdown requests will effectively "kill -KILL" your application.
| |
| getDesktop | back to summary |
|---|---|
| public static synchronized Desktop getDesktop() Returns the
| |
| isDesktopSupported | back to summary |
|---|---|
| public static boolean isDesktopSupported() Tests whether this class is supported on the current platform.
If it's supported, use
| |
| isSupported | back to summary |
|---|---|
| public boolean isSupported(Desktop. Tests whether an action is supported on the current platform. Even when the platform supports an action, a file or URI may
not have a registered application for the action. For example,
most of the platforms support the
| |
| back to summary | |
|---|---|
| public void mail() throws IOException Launches the mail composing window of the user default mail client.
| |
| back to summary | |
|---|---|
| public void mail(URI mailtoURI) throws IOException Launches the mail composing window of the user default mail
client, filling the message fields specified by a A
| |
| moveToTrash | back to summary |
|---|---|
| public boolean moveToTrash(File file) Moves the specified file to the trash.
| |
| open | back to summary |
|---|---|
| public void open(File file) throws IOException Launches the associated application to open the file. If the specified file is a directory, the file manager of the current platform is launched to open it.
| |
| openHelpViewer | back to summary |
|---|---|
| public void openHelpViewer() Opens the native help viewer application. Implementation Note Please note that for Mac OS, it opens the native help viewer application if a Help Book has been added to the application bundler and registered in the Info.plist with CFBundleHelpBookFolder
| |
| back to summary | |
|---|---|
| public void print(File file) throws IOException Prints a file with the native desktop printing facility, using the associated application's print command.
| |
| removeAppEventListener | back to summary |
|---|---|
| public void removeAppEventListener(final SystemEventListener listener) Removes sub-types of | |
| requestForeground | back to summary |
|---|---|
| public void requestForeground(final boolean allWindows) Requests this application to move to the foreground.
| |
| setAboutHandler | back to summary |
|---|---|
| public void setAboutHandler(final AboutHandler aboutHandler) Installs a handler to show a custom About window for your application.
Setting the
| |
| setDefaultMenuBar | back to summary |
|---|---|
| public void setDefaultMenuBar(final JMenuBar menuBar) Sets the default menu bar to use when there are no active frames.
| |
| setOpenFileHandler | back to summary |
|---|---|
| public void setOpenFileHandler(final OpenFilesHandler openFileHandler) Installs the handler which is notified when the application is asked to open a list of files. Implementation Note Please note that for macOS, notifications
are only sent if the Java app is a bundled application,
with a
| |
| setOpenURIHandler | back to summary |
|---|---|
| public void setOpenURIHandler(final OpenURIHandler openURIHandler) Installs the handler which is notified when the application is asked to
open a URL.
Setting the handler to Implementation Note Please note that for macOS, notifications
are only sent if the Java app is a bundled application,
with a
| |
| setPreferencesHandler | back to summary |
|---|---|
| public void setPreferencesHandler(final PreferencesHandler preferencesHandler) Installs a handler to show a custom Preferences window for your application.
Setting the
| |
| setPrintFileHandler | back to summary |
|---|---|
| public void setPrintFileHandler(final PrintFilesHandler printFileHandler) Installs the handler which is notified when the application is asked to print a list of files. Implementation Note Please note that for macOS, notifications
are only sent if the Java app is a bundled application,
with a
| |
| setQuitHandler | back to summary |
|---|---|
| public void setQuitHandler(final QuitHandler quitHandler) Installs the handler which determines if the application should quit. The
handler is passed a one-shot
| |
| setQuitStrategy | back to summary |
|---|---|
| public void setQuitStrategy(final QuitStrategy strategy) Sets the default strategy used to quit this application. The default is calling SYSTEM_EXIT_0.
| |
Desktop#isSupported
method to determine if the given action is supported by the
current platform.
java.awt.Desktop#isSupported(java.awt.Desktop.Action)
| Modifier and Type | Field and Description |
|---|---|
| public static final Desktop. | APP_ABOUT
Represents an AboutHandler |
| public static final Desktop. | APP_EVENT_FOREGROUND
Represents an AppForegroundListener |
| public static final Desktop. | APP_EVENT_HIDDEN
Represents an AppHiddenListener |
| public static final Desktop. | APP_EVENT_REOPENED
Represents an AppReopenedListener |
| public static final Desktop. | APP_EVENT_SCREEN_SLEEP
Represents a ScreenSleepListener |
| public static final Desktop. | APP_EVENT_SYSTEM_SLEEP
Represents a SystemSleepListener |
| public static final Desktop. | APP_EVENT_USER_SESSION
Represents a UserSessionListener |
| public static final Desktop. | APP_HELP_VIEWER
Represents a HelpViewer |
| public static final Desktop. | APP_MENU_BAR
Represents a menu bar |
| public static final Desktop. | APP_OPEN_FILE
Represents an OpenFilesHandler |
| public static final Desktop. | APP_OPEN_URI
Represents an OpenURIHandler |
| public static final Desktop. | APP_PREFERENCES
Represents a PreferencesHandler |
| public static final Desktop. | APP_PRINT_FILE
Represents a PrintFilesHandler |
| public static final Desktop. | APP_QUIT_HANDLER
Represents a QuitHandler |
| public static final Desktop. | APP_QUIT_STRATEGY
Represents a QuitStrategy |
| public static final Desktop. | APP_REQUEST_FOREGROUND
Represents a requestForeground |
| public static final Desktop. | APP_SUDDEN_TERMINATION
Represents a SuddenTermination |
| public static final Desktop. | BROWSE
Represents a "browse" action. |
| public static final Desktop. | BROWSE_FILE_DIR
Represents a browse file directory |
| public static final Desktop. | EDIT
Represents an "edit" action. |
| public static final Desktop. | MAIL
Represents a "mail" action. |
| public static final Desktop. | MOVE_TO_TRASH
Represents a move to trash |
| public static final Desktop. | OPEN
Represents an "open" action. |
| public static final Desktop. | PRINT
Represents a "print" action. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Desktop. | |
| public static Desktop. |
| APP_ABOUT | back to summary |
|---|---|
| public static final Desktop. Represents an AboutHandler
| |
| APP_EVENT_FOREGROUND | back to summary |
|---|---|
| public static final Desktop. Represents an AppForegroundListener
| |
| APP_EVENT_HIDDEN | back to summary |
|---|---|
| public static final Desktop. Represents an AppHiddenListener
| |
| APP_EVENT_REOPENED | back to summary |
|---|---|
| public static final Desktop. Represents an AppReopenedListener
| |
| APP_EVENT_SCREEN_SLEEP | back to summary |
|---|---|
| public static final Desktop. Represents a ScreenSleepListener
| |
| APP_EVENT_SYSTEM_SLEEP | back to summary |
|---|---|
| public static final Desktop. Represents a SystemSleepListener
| |
| APP_EVENT_USER_SESSION | back to summary |
|---|---|
| public static final Desktop. Represents a UserSessionListener
| |
| APP_HELP_VIEWER | back to summary |
|---|---|
| public static final Desktop. Represents a HelpViewer
| |
| APP_MENU_BAR | back to summary |
|---|---|
| public static final Desktop. Represents a menu bar
| |
| APP_OPEN_FILE | back to summary |
|---|---|
| public static final Desktop. Represents an OpenFilesHandler
| |
| APP_OPEN_URI | back to summary |
|---|---|
| public static final Desktop. Represents an OpenURIHandler
| |
| APP_PREFERENCES | back to summary |
|---|---|
| public static final Desktop. Represents a PreferencesHandler
| |
| APP_PRINT_FILE | back to summary |
|---|---|
| public static final Desktop. Represents a PrintFilesHandler
| |
| APP_QUIT_HANDLER | back to summary |
|---|---|
| public static final Desktop. Represents a QuitHandler
| |
| APP_QUIT_STRATEGY | back to summary |
|---|---|
| public static final Desktop. Represents a QuitStrategy
| |
| APP_REQUEST_FOREGROUND | back to summary |
|---|---|
| public static final Desktop. Represents a requestForeground
| |
| APP_SUDDEN_TERMINATION | back to summary |
|---|---|
| public static final Desktop. Represents a SuddenTermination
| |
| BROWSE | back to summary |
|---|---|
| public static final Desktop. Represents a "browse" action.
| |
| BROWSE_FILE_DIR | back to summary |
|---|---|
| public static final Desktop. Represents a browse file directory
| |
| EDIT | back to summary |
|---|---|
| public static final Desktop. Represents an "edit" action.
| |
| back to summary | |
|---|---|
| public static final Desktop. Represents a "mail" action.
| |
| MOVE_TO_TRASH | back to summary |
|---|---|
| public static final Desktop. Represents a move to trash
| |
| OPEN | back to summary |
|---|---|
| public static final Desktop. Represents an "open" action.
| |
| back to summary | |
|---|---|
| public static final Desktop. Represents a "print" action.
| |
| Action | back to summary |
|---|---|
| private Action() | |
| valueOf | back to summary |
|---|---|
| public static Desktop. | |
| values | back to summary |
|---|---|
| public static Desktop. | |