JAVA UI drag and drop function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.