文档

Java™ 教程-Java Tutorials 中文版
导出方法
Trail: Creating a GUI With JFC/Swing
Lesson: Drag and Drop and Data Transfer
Section: TransferHandler Class

导出方法

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