Top Description Methods
java.awt.peer

public Interface DesktopPeer

Known Direct Implementers
sun.awt.X11.XDesktopPeer
Imports
java.awt.Desktop.Action, java.awt.desktop.AboutHandler, .OpenFilesHandler, .OpenURIEvent, .OpenURIHandler, .PreferencesEvent, .PreferencesHandler, .PrintFilesHandler, .QuitHandler, .QuitStrategy, .SystemEventListener, java.io.File, .IOException, java.net.URI, javax.swing.JMenuBar

The DesktopPeer interface provides methods for the operation of open, edit, print, browse and mail with the given URL or file, by launching the associated application.

Each platform has an implementation class for this interface.

Method Summary

Modifier and TypeMethod and Description
public default void
addAppEventListener(final SystemEventListener
listener
listener
)

Adds sub-types of SystemEventListener to listen for notifications from the native system.

public void
browse(URI
the given URI.
uri
)

Launches the user default browser to display the given URI.

public default boolean

Returns:

returns true if successfully opened
browseFileDirectory
(File
the file
file
)

Opens a folder containing the file in a default system file manager.

public default void
disableSuddenTermination()

Prevents this application from being suddenly terminated.

public void
edit(File
the given file.
file
)

Launches the associated editor and opens the given file for editing.

public default void
enableSuddenTermination()

Enables this application to be suddenly terminated.

public boolean

Returns:

true if the given action is supported on the current platform; false otherwise.
isSupported
(Desktop.Action
the action type to be tested if it's supported on the current platform.
action
)

Returns whether the given action is supported on the current platform.

public void
mail(URI
represents a mailto URL with specified values of the message. The syntax of mailto URL is defined by RFC2368: The mailto URL scheme
mailtoURL
)

Launches the mail composing window of the user default mail client, filling the message fields including to, cc, etc, with the values specified by the given mailto URL.

public default boolean

Returns:

returns true if successfully moved the file to the trash.
moveToTrash
(File
the file
file
)

Moves the specified file to the trash.

public void
open(File
the given file.
file
)

Launches the associated application to open the given file.

public default void
openHelpViewer()

Opens the native help viewer application.

public default void
removeAppEventListener(final SystemEventListener
listener
listener
)

Removes sub-types of SystemEventListener to listen for notifications from the native system.

public default 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 default void
setAboutHandler(final AboutHandler
the handler to respond to the AboutHandler#handleAbout )} message
aboutHandler
)

Installs a handler to show a custom About window for your application.

public default 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 default void
setOpenFileHandler(final OpenFilesHandler
handler
openFileHandler
)

Installs the handler which is notified when the application is asked to open a list of files.

public default void
setOpenURIHandler(final OpenURIHandler
handler
openURIHandler
)

Installs the handler which is notified when the application is asked to open a URL.

public default void
setPreferencesHandler(final PreferencesHandler preferencesHandler)

Installs a handler to show a custom Preferences window for your application.

public default void
setPrintFileHandler(final PrintFilesHandler
handler
printFileHandler
)

Installs the handler which is notified when the application is asked to print a list of files.

public default 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 default void
setQuitStrategy(final QuitStrategy
the way this application should be shutdown
strategy
)

Sets the default strategy used to quit this application.

Method Detail

addAppEventListenerback to summary
public default void addAppEventListener(final SystemEventListener listener)

Adds sub-types of SystemEventListener to listen for notifications from the native system.

Parameters
listener:SystemEventListener

listener

See Also
java.awt.desktop.AppForegroundListener, java.awt.desktop.AppHiddenListener, java.awt.desktop.AppReopenedListener, java.awt.desktop.ScreenSleepListener, java.awt.desktop.SystemSleepListener, java.awt.desktop.UserSessionListener
browseback to summary
public void browse(URI uri) throws IOException

Launches the user default browser to display the given URI.

Parameters
uri:URI

the given URI.

Exceptions
IOException:
If the user default browser is not found, or it fails to be launched.
browseFileDirectoryback to summary
public default boolean browseFileDirectory(File file)

Opens a folder containing the file in a default system file manager.

Parameters
file:File

the file

Returns:boolean

returns true if successfully opened

disableSuddenTerminationback to summary
public default void disableSuddenTermination()

Prevents this application from being suddenly terminated.

See Also
java.awt.Desktop#enableSuddenTermination()
editback to summary
public void edit(File file) throws IOException

Launches the associated editor and opens the given file for editing. The associated editor is registered to be the default editor for the file type of the given file.

Parameters
file:File

the given file.

Exceptions
IOException:
If the given file has no associated editor, or the associated application fails to be launched.
enableSuddenTerminationback to summary
public default void enableSuddenTermination()

Enables this application to be suddenly terminated.

See Also
java.awt.Desktop#disableSuddenTermination()
isSupportedback to summary
public boolean isSupported(Desktop.Action action)

Returns whether the given action is supported on the current platform.

Parameters
action:Desktop.Action

the action type to be tested if it's supported on the current platform.

Returns:boolean

true if the given action is supported on the current platform; false otherwise.

mailback to summary
public void mail(URI mailtoURL) throws IOException

Launches the mail composing window of the user default mail client, filling the message fields including to, cc, etc, with the values specified by the given mailto URL.

Parameters
mailtoURL:URI

represents a mailto URL with specified values of the message. The syntax of mailto URL is defined by RFC2368: The mailto URL scheme

Exceptions
IOException:
If the user default mail client is not found, or it fails to be launched.
External Specification
https://www.rfc-editor.org/info/rfc2368
moveToTrashback to summary
public default boolean moveToTrash(File file)

Moves the specified file to the trash.

Parameters
file:File

the file

Returns:boolean

returns true if successfully moved the file to the trash.

openback to summary
public void open(File file) throws IOException

Launches the associated application to open the given file. The associated application is registered to be the default file viewer for the file type of the given file.

Parameters
file:File

the given file.

Exceptions
IOException:
If the given file has no associated application, or the associated application fails to be launched.
openHelpViewerback to summary
public default void openHelpViewer()

Opens the native help viewer application.

removeAppEventListenerback to summary
public default void removeAppEventListener(final SystemEventListener listener)

Removes sub-types of SystemEventListener to listen for notifications from the native system.

Parameters
listener:SystemEventListener

listener

See Also
java.awt.desktop.AppForegroundListener, java.awt.desktop.AppHiddenListener, java.awt.desktop.AppReopenedListener, java.awt.desktop.ScreenSleepListener, java.awt.desktop.SystemSleepListener, java.awt.desktop.UserSessionListener
requestForegroundback to summary
public default void requestForeground(final boolean allWindows)

Requests this application to move to the foreground.

Parameters
allWindows:boolean

if all windows of this application should be moved to the foreground, or only the foremost one

setAboutHandlerback to summary
public default void setAboutHandler(final AboutHandler aboutHandler)

Installs a handler to show a custom About window for your application.

Setting the AboutHandler to null reverts it to the default behavior.

Parameters
aboutHandler:AboutHandler

the handler to respond to the AboutHandler#handleAbout )} message

setDefaultMenuBarback to summary
public default void setDefaultMenuBar(final JMenuBar menuBar)

Sets the default menu bar to use when there are no active frames.

Parameters
menuBar:JMenuBar

to use when no other frames are active

setOpenFileHandlerback to summary
public default void setOpenFileHandler(final OpenFilesHandler openFileHandler)

Installs the handler which is notified when the application is asked to open a list of files.

Parameters
openFileHandler:OpenFilesHandler

handler

setOpenURIHandlerback to summary
public default void setOpenURIHandler(final OpenURIHandler openURIHandler)

Installs the handler which is notified when the application is asked to open a URL. Setting the handler to null causes all OpenURIHandler#openURI(OpenURIEvent) requests to be enqueued until another handler is set.

Parameters
openURIHandler:OpenURIHandler

handler

setPreferencesHandlerback to summary
public default void setPreferencesHandler(final PreferencesHandler preferencesHandler)

Installs a handler to show a custom Preferences window for your application.

Setting the PreferencesHandler to null reverts it to the default behavior

Parameters
preferencesHandler:PreferencesHandler

the handler to respond to the java.awt.desktop.PreferencesHandler#handlePreferences(PreferencesEvent)

setPrintFileHandlerback to summary
public default void setPrintFileHandler(final PrintFilesHandler printFileHandler)

Installs the handler which is notified when the application is asked to print a list of files.

Parameters
printFileHandler:PrintFilesHandler

handler

setQuitHandlerback to summary
public default void setQuitHandler(final QuitHandler quitHandler)

Installs the handler which determines if the application should quit.

Parameters
quitHandler:QuitHandler

the handler that is called when the application is asked to quit

See Also
java.awt.Desktop#setQuitHandler(java.awt.desktop.QuitHandler)
setQuitStrategyback to summary
public default void setQuitStrategy(final QuitStrategy strategy)

Sets the default strategy used to quit this application. The default is calling SYSTEM_EXIT_0.

Parameters
strategy:QuitStrategy

the way this application should be shutdown