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
    Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.
    boolean
    Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    May cause performance issues, deadlocks and hangs.
    final Class<? extends Object>
    Answers the unique instance of java.lang.Class which represents the class of the receiver.
    int
    Answers an integer hash code for the receiver.
    final void
    Causes one thread which is waiting on the receiver to be made ready to run.
    final void
    Causes all threads which are waiting on the receiver to be made ready to run.
    Answers a string containing a concise, human-readable description of the receiver.
    final void
    Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated by notify or notifyAll).
    final void
    wait(long time)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
    final void
    wait(long time, int frac)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.