NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en: http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com.
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂ­tulo en concreto puede realizar una donación directa mediante Paypal:
Default DnD Support (The Java™ Tutorials > Creating a GUI with JFC/Swing > Drag and Drop and Data Transfer)
Trail: Creating a GUI with JFC/Swing
Lesson: Drag and Drop and Data Transfer
Default DnD Support
Home Page > Creating a GUI with JFC/Swing > Drag and Drop and Data Transfer
Default DnD Support
Technically speaking, the framework for drag and drop supports all Swing components — the data transfer mechanism is built into every JComponent. If you wanted, you could implement drop support for a JSlider so that it could fully participate in data transfer. While JSlider does not support drop by default, the components you would want (and expect) to support drag and drop do provide specialized built-in support.

The following components recognize the drag gesture once the setDragEnabled(true) method is invoked on the component. For example, once you invoke myColorChooser.setDragEnabled(true) you can drag colors from your color chooser:

The following components support drop out of the box. If you are using one of these components, your work is done.

The framework for drop is in place for the following components, but you need to plug in a small amount of code to customize the support for your needs.

For these critical components, Swing performs the drop location calculations and rendering; it allows you to specify a drop mode; and it handles component specific details, such as tree expansions. Your work is fairly minimal.

Note: You can also install drop support on top-level containers, such as JFrame and JDialog. You can learn more about this in Top-Level Drop.
Previous page: Introduction to DnD
Next page: Demo - BasicDnD