Hello all
Does Caret Event only for one component only ?
I tried to find example for more than one TextField which
added with CaretListener,but cannot find one.
Anybody know website or has example like I need ?
I need to know how to detect which component arise the CaretEvent ?


thank you
denny

hello mKorbel
I tried ,but give me error

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextField textField = new JTextField();
	textField.setActionCommand("testing");
	
	textField.addCaretListener(new CaretListener() {
	if("testing".equals(e.getActionCommand()))
	{
    public void caretUpdate(CaretEvent e) {
    System.out.println(e);
	}
    }
    });

    frame.add(new JScrollPane(textField));

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

If you have one listener for multiple text fields then you can get the source of the event from the CaretEvent that's passed as a parameter to your caretUpdate method, eg

public void caretUpdate(CaretEvent e) {
   if (e.getSource() == myFirstTextField) { ...
   else if ((e.getSource() == mySecondTextField) { ...
This question has already been answered. Start a new discussion instead.