Class Desktop

java.lang.Object
java.awt.Desktop

public class Desktop extends Object
The Desktop class allows interact with various desktop capabilities.

Supported operations include:

  • launching the user-default browser to show a specified URI;
  • launching the user-default mail client with an optional mailto URI;
  • launching a registered application to open, edit or print a specified file.

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.Action 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.Action 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.

Since:
1.6
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Represents an action type.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds sub-types of SystemEventListener to listen for notifications from the native system.
    void
    browse(URI uri)
    Launches the default browser to display a URI.
    void
    Opens a folder containing the file and selects it in a default system file manager.
    void
    Prevents this application from being suddenly terminated.
    void
    edit(File file)
    Launches the associated editor application and opens a file for editing.
    void
    Enables this application to be suddenly terminated.
    static Desktop
    Returns the Desktop instance of the current desktop context.
    static boolean
    Tests whether this class is supported on the current platform.
    boolean
    Tests whether an action is supported on the current platform.
    void
    Launches the mail composing window of the user default mail client.
    void
    mail(URI mailtoURI)
    Launches the mail composing window of the user default mail client, filling the message fields specified by a mailto: URI.
    boolean
    Moves the specified file to the trash.
    void
    open(File file)
    Launches the associated application to open the file.
    void
    Opens the native help viewer application.
    void
    print(File file)
    Prints a file with the native desktop printing facility, using the associated application's print command.
    void
    Removes sub-types of SystemEventListener to listen for notifications from the native system.
    void
    requestForeground(boolean allWindows)
    Requests this application to move to the foreground.
    void
    Installs a handler to show a custom About window for your application.
    void
    Sets the default menu bar to use when there are no active frames.
    void
    Installs the handler which is notified when the application is asked to open a list of files.
    void
    Installs the handler which is notified when the application is asked to open a URL.
    void
    Installs a handler to show a custom Preferences window for your application.
    void
    Installs the handler which is notified when the application is asked to print a list of files.
    void
    Installs the handler which determines if the application should quit.
    void
    Sets the default strategy used to quit this application.

    Methods declared in class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
    Creates and returns a copy of this object.
    boolean
    Indicates whether some other object is "equal to" this one.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Finalization is deprecated and subject to removal in a future release.
    final Class<?>
    Returns the runtime class of this Object.
    int
    Returns a hash code value for this object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
    final void
    wait(long timeoutMillis)
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
    final void
    wait(long timeoutMillis, int nanos)
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.