java.awt

Class Desktop


  • public class Desktop
    extends Object
    The Desktop class allows a Java application to launch associated applications registered on the native desktop to handle a URI or a file.

    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.

    An application is registered to a URI or file type; for example, the "sxi" file extension is typically registered to StarOffice. 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
    • Method Detail

      • isDesktopSupported

        public static boolean isDesktopSupported()
        Tests whether this class is supported on the current platform. If it's supported, use getDesktop() to retrieve an instance.
        Returns:
        true if this class is supported on the current platform; false otherwise
        See Also:
        getDesktop()
      • isSupported

        public boolean isSupported(Desktop.Action action)
        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 Desktop.Action.OPEN action. But for a specific file, there may not be an application registered to open it. In this case, isSupported(java.awt.Desktop.Action) may return true, but the corresponding action method will throw an IOException.

        Parameters:
        action - the specified Desktop.Action
        Returns:
        true if the specified action is supported on the current platform; false otherwise
        See Also:
        Desktop.Action
      • browse

        public void browse(URI uri)
                    throws IOException
        Launches the default browser to display a URI. If the default browser is not able to handle the specified URI, the application registered for handling URIs of the specified type is invoked. The application is determined from the protocol and path of the URI, as defined by the URI class.

        If the calling thread does not have the necessary permissions, and this is invoked from within an applet, AppletContext.showDocument() is used. Similarly, if the calling does not have the necessary permissions, and this is invoked from within a Java Web Started application, BasicService.showDocument() is used.

        Parameters:
        uri - the URI to be displayed in the user default browser
        Throws:
        NullPointerException - if uri is null
        UnsupportedOperationException - if the current platform does not support the Desktop.Action.BROWSE action
        IOException - if the user default browser is not found, or it fails to be launched, or the default handler application failed to be launched
        SecurityException - if a security manager exists and it denies the AWTPermission("showWindowWithoutWarningBanner") permission, or the calling thread is not allowed to create a subprocess; and not invoked from within an applet or Java Web Started application
        IllegalArgumentException - if the necessary permissions are not available and the URI can not be converted to a URL
        See Also:
        URI, AWTPermission, AppletContext
      • mail

        public void mail()
                  throws IOException
        Launches the mail composing window of the user default mail client.
        Throws:
        UnsupportedOperationException - if the current platform does not support the Desktop.Action.MAIL action
        IOException - if the user default mail client is not found, or it fails to be launched
        SecurityException - if a security manager exists and it denies the AWTPermission("showWindowWithoutWarningBanner") permission, or the calling thread is not allowed to create a subprocess
        See Also:
        AWTPermission
      • mail

        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 mailto: URI.

        A mailto: URI can specify message fields including "to", "cc", "subject", "body", etc. See The mailto URL scheme (RFC 2368) for the mailto: URI specification details.

        Parameters:
        mailtoURI - the specified mailto: URI
        Throws:
        NullPointerException - if the specified URI is null
        IllegalArgumentException - if the URI scheme is not "mailto"
        UnsupportedOperationException - if the current platform does not support the Desktop.Action.MAIL action
        IOException - if the user default mail client is not found or fails to be launched
        SecurityException - if a security manager exists and it denies the AWTPermission("showWindowWithoutWarningBanner") permission, or the calling thread is not allowed to create a subprocess
        See Also:
        URI, AWTPermission

Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-java/awt/desktop.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : https://docs.oracle.com

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut