The DragGestureRecognizer

The user gesture or set of gestures initiating a drag-and-drop operation will vary per component, platform, and device. A DragGestureRecognizer protects you from platform dependencies by enclosing these implementation details. The instance method dragSource.createDefaultDragGestureRecognizer() obtains a recognizer and associates it with a component, action, and DragGestureListener. This example creates a subclass of a Swinglabel (JLabel). In its constructor, the necessary classes and associations are made for it to act as a drag source for either a copy or a move operation. Listeners will be discussed next. The code in Listing 12.1 represents the first steps in making any draggable component.

Listing 12.1 First Steps ...

Get JavaBeans Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.