Documentation

Export Methods
Trail: Creating a GUI With JFC/Swing
Lesson: Drag and Drop and Data Transfer
Section: TransferHandler Class

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.


Previous page: TransferHandler Class
Next page: Import Methods