Drag and drop between JTextArea and JTextField : Drag and Drop « JDK 6 « Java






Drag and drop between JTextArea and JTextField

 

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class DnDBetweenJTextAreaAndJTextFieldDemo {
  public static void main(String[] args) {
    JFrame frame = new JFrame("Drag and Drop Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new JPanel());
    JTextField textField = new JTextField(25);
    textField.setText("www.java2s.com");
    frame.add(textField);

    JTextArea textArea = new JTextArea(4, 25);
    textArea.setText("Demonstrating\ndrag and drop");
    frame.getContentPane().add(new JScrollPane(textArea));
    textArea.setDragEnabled(true);
    textField.setDragEnabled(true);
    frame.pack();
    frame.setVisible(true);

  }
}

        








Related examples in the same category

1.Transfer both Text and Color between JTextField and JTextArea
2.Drag and drop between JList and JTextField
3.DropMode.ON
4.DropMode.INSERT
5.DropMode.ON_OR_INSERT
6.Set tree DropMode to DropMode.USE_SELECTION
7.Set tree drag mode to DropMode.ON
8.Set tree drag mode to DropMode.INSERT
9.Set tree drag mode to DropMode.ON_OR_INSERT