Drag and drop text between JTextArea in Java
Description
The following code shows how to drag and drop text between JTextArea.
Example
/*from w w w .ja va 2s.co m*/
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
JTextArea textarea = new JTextArea();
textarea.setDragEnabled(true);
textarea.setText("Drag target");
frame.getContentPane().add(BorderLayout.CENTER, textarea);
JTextField textarea1 = new JTextField();
textarea1.setText("Drop target");
frame.getContentPane().add(BorderLayout.SOUTH, textarea1);
frame.setSize(500, 300);
frame.setVisible(true);
frame.setLocation(100, 100);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »