Java JTextArea handle mouse move event

Description

Java JTextArea handle mouse move event

import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JFrame;
import javax.swing.JTextArea;

public class Main extends JFrame {
   public Main() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setSize(400, 400);//from   ww w. j a  v a 2  s  .co  m

      JTextArea textArea = new JTextArea("drag it...");
      textArea.addMouseMotionListener(new MouseMotionAdapter() {
         public void mouseDragged(MouseEvent e) {
            System.out.println("Mouse Dragged...");
         }

         public void mouseMoved(MouseEvent e) {
            System.out.println("Mouse Moved...");
         }
      });

      getContentPane().add(textArea);
   }

   public static void main(String[] args) {
      new Main().setVisible(true);
   }
}



PreviousNext

Related