The Java GUI drag-and-drop feature is a useful and relatively advanced feature.
A small number of GUI controls are supported
They have the dragenabled attribute. These jcomponent include:
Javax.swing.JColorChooser
Javax.swing.JFileChooser
Javax.swing.JList
Javax.swing.JTable
Javax.swing.JTree
Javax.swing.text.JTextComponent
Most of the controls do not support the absence of this property, especially the commonly used JPanel and jframe.
An easy way is to implement the inherited Droptargetadapter class, which is an adapter that implements the Droptargetlistener interface, which implements the drop method.
The method has a Droptargetdropevent object parameter, the drop inside the call order is as follows
1. Call the Acceptdrop method of this object, need an int parameter, use the constant in dndconstants (Drag and Drop constant Class)
2. Obtain the Gettransferable object of the Dtde object, in the Gettransferdata method that calls transferable. The parameter is Dataflavor.javafilelistflavor (also a dataflavor).
DataFlavor involved in the transmission of some information, some complex, temporarily do not understand.
3. Directly inside the control, a new Droptargetadapter object can be.
The question of Drag and drop simply involves two parts: Drag Source, Drop target and transferable where Drag came from,
And where the drop goes, as well as the data transferred.
No in-depth understanding, the following blog write more detailed, have time to see.
Http://blog.sina.com.cn/s/blog_799d8220010196nj.html
JAVA UI drag and drop function