Java >
Guidelines Home Page >  Java Look and Feel Design Guidelines
>
Part II: Fundamental Java Application Design
>
6: Behavior
> Drag-and-Drop Operations
  Previous Next Contents/Index/Search


Drag-and-Drop Operations

Drag-and-drop operations include moving, copying, or linking selected objects by dragging them from one location and dropping them over another. These operations provide a convenient and intuitive way to perform many tasks using direct manipulation. Common examples of drag and drop in the user interface are moving files by dragging file icons between folders or dragging selected text from one document to another. The Java 2 platform supports drag and drop within an application, between two Java applications, or between a Java application and a native application. For example, on a Microsoft Windows system, users can drag a text selection from a Java application and drop it into a Microsoft Word document.

  Provide keyboard equivalents for all drag-and-drop operations (such as Cut, Copy, and Paste).

Typical Drag and Drop

Drag and drop in Java applications is similar to dragging behavior on other platforms. Users press mouse button 1 while the pointer is over a source object and then drag the object by moving the pointer while holding down the mouse button. To drop the object, users release the button when the pointer is over a suitable destination. A successful drop triggers an action that depends on the nature of the source and destination. If the drag source is part of a range selection, the entire selection (for example, several file icons or a range of text) is dragged. To cancel a drag-and-drop operation after it has started, users drop the object over an invalid destination or press the Escape key.

Pointer and Destination Feedback

During any drag-and-drop operation, your Java look and feel application needs to give visual feedback using the pointer and the destination.

  Provide the user with feedback that a drag operation is in progress by changing the shape of the pointer when the drag is initiated. Use different pointers to distinguish operations (such as copying or moving).

  Provide destination feedback so users know where the dragged object can be dropped. Use one or both of the following methods to provide destination feedback:

  • Change the shape of the pointer to reflect whether the object is over a possible drop target.
  • Highlight drop targets when the pointer is over them to indicate that they can accept the selection or source.

  Java objects are specified by their MIME (Multipurpose Internet Mail Extensions) types, and the Java TM runtime environment automatically translates back and forth between MIME types and system-native types as needed. As an object is dragged over potential targets, each potential target can query the drag source to obtain a list of available data types and then compare that with the list of data types that it can accept. For example, when dragging a range of text, the source might be able to deliver the text in a number of different encodings such as plain text, styled text, or HTML text. If there is a match in data types, potential targets should be highlighted as the pointer passes over them to indicate that they can accept the dragged object.


Java Look and Feel Design Guidelines, second edition.
Copyright 2001. Sun Microsystems, Inc. All Rights Reserved.
Previous Next Contents/Index/Search
Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve
JavaOne Banner Java 8 banner (182)