CaretEeventListener.java Source code

Java tutorial

Introduction

Here is the source code for CaretEeventListener.java

Source

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;

public class CaretEeventListener {

    public static void main(String[] a) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JTextField textField = new JTextField();

        textField.addCaretListener(new CaretListener() {

            public void caretUpdate(CaretEvent e) {
                System.out.println(e);

            }
        });

        frame.add(new JScrollPane(textField));

        frame.setSize(300, 200);
        frame.setVisible(true);
    }

}