This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.awt
class Desktop

java.lang.Object extended by java.awt.Desktop

Most common way to construct:

Desktop desktop = Desktop.getDesktop();

Based on 25 examples


public class Desktop
extends Object

The {@code Desktop} class allows a Java application to launch associated applications registered on the native desktop to handle a {@link java.net.URI} or a file.

Supported operations include:

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 {@code "sxi"} file extension is typically registered to StarOffice. The mechanism of registereing, accessing, and launching the associated application is platform-dependent.

Each operation is an action type represented by the {@link 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.


Nested Class Summary
static enum

           Represents an action type.
 
Method Summary
 void
browse(URI uri)

          Launches the default browser to display a .
 void
edit(File file)

          Launches the associated editor application and opens a file for editing.
static Desktop

          Returns the Desktop instance of the current browser 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 URI.
 void
open(File file)

          Launches the associated application to open the file.
 void
print(File file)

          Prints a file with the native desktop printing facility, using the associated application's print command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

browse

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

If the calling thread does not have the necessary permissions, and this is invoked from within an applet, {@code 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, {@code BasicService.showDocument()} is used.

Parameters:
uri - the URI to be displayed in the user default browser
Throws:
IOException - if the user default browser is not found, or it fails to be launched, or the default handler application failed to be launched

edit

public void edit(File file)
          throws IOException
Launches the associated editor application and opens a file for editing.

Parameters:
file - the file to be opened for editing
Throws:
IOException - if the specified file has no associated editor, or the associated application fails to be launched

getDesktop

public static synchronized Desktop getDesktop()
Returns the Desktop instance of the current browser context. On some platforms the Desktop API may not be supported; use the {@link #isDesktopSupported} method to determine if the current desktop is supported.

Returns:
the Desktop instance of the current browser context

isDesktopSupported

public static boolean isDesktopSupported()
Tests whether this class is supported on the current platform. If it's supported, use {@link #getDesktop()} to retrieve an instance.

Returns:
true if this class is supported on the current platform; false otherwise

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 {@link Desktop.Action#OPEN} action. But for a specific file, there may not be an application registered to open it. In this case, {@link #isSupported} may return {@code true}, but the corresponding action method will throw an {@link IOException}.

Parameters:
action - the specified {@link Action}
Returns:
true if the specified action is supported on the current platform; false otherwise

mail

public void mail()
          throws IOException
Launches the mail composing window of the user default mail client.

Throws:
IOException - if the user default mail client is not found, or it fails to be launched

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 {@code mailto:} URI.

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

Parameters:
mailtoURI - the specified {@code mailto:} URI
Throws:
IOException - if the user default mail client is not found or fails to be launched

open

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.

Parameters:
file - the file to be opened with the associated application
Throws:
IOException - if the specified file has no associated application or the associated application fails to be launched

print

public void print(File file)
           throws IOException
Prints a file with the native desktop printing facility, using the associated application's print command.

Parameters:
file - the file to be printed
Throws:
IOException - if the specified file has no associated application that can be used to print it


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.