Glisser-Déposer: Exemple de Glisser-déposer(DnD) entre TextArea et TextField.

Author:


{filelink=850}


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

public class DnDEntreJTextAreaEtJTextField {
  public static void main(String[] args) {
    JFrame frame = new JFrame("Demo Glisser-déposer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new JPanel());
    JTextField textField = new JTextField(25);
    textField.setText("www.mesexemples.com");
    frame.add(textField);

    JTextArea textArea = new JTextArea(4, 25);
    textArea.setText("Glisses Moi vers le champ de texte");
    frame.getContentPane().add(new JScrollPane(textArea));
    textArea.setDragEnabled(true);
    textField.setDragEnabled(true);
    frame.pack();
    frame.setVisible(true);

  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *