A browser with JavaScript enabled is required for this page to operate properly.
Trail: Creating a GUI With JFC/Swing
Lesson: Drag and Drop and Data Transfer
Section: TransferHandler Class
Export Methods
Home Page > Creating a GUI With JFC/Swing > Drag and Drop and Data Transfer

Export Methods

The first set of methods we will examine are used for exporting data from a component. These methods are invoked for the drag gesture, or the cut/copy action, when the component in question is the source of the operation. The TransferHandler methods for exporting data are:

Sample Export Methods

Here are some sample implementations of the export methods:

int getSourceActions(JComponent c) {
    return COPY_OR_MOVE;
}

Transferable createTransferable(JComponent c) {
    return new StringSelection(c.getSelection());
}

void exportDone(JComponent c, Transferable t, int action) {
    if (action == MOVE) {
        c.removeSelection();
    }
}

Next we will look at the TransferHandler methods required for data import.


Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: TransferHandler Class
Next page: Import Methods