0

In my program, I wanted to invoke an ActionEvent on a TextField named descField, when the focus is lost. I used dispatchEvent successfully. When I changed the TextField to a JTextField, it doesn't work. I would be grateful for some help (I am an amateur with Java). Here is the dispatcher which is the focusLost method of my JTextField:

    public void focusLost(FocusEvent f) {
        ActionEvent action = new ActionEvent(descField, ActionEvent.ACTION_PERFORMED, "focus_lost");
        descField.dispatchEvent(action); // Causes actionPerformed to be invoked
        // Does not work with JTextArea
    } //focusLost

How can I make it work using JTextField, instead of TextField?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • For better help sooner, post an [SSCCE](http://sscce.org/). *"I would be grateful for some help"* I'd be grateful for a question. What is your question? – Andrew Thompson Apr 29 '12 at 17:03
  • Sorry Andrew, I do not know what an SSCCE is and this is my first question. The question is how can I make it work using JTextField, instead of TextField? – user1364337 Apr 29 '12 at 18:56
  • *"I do not know what an SSCCE is.."* That is why I linked to the document that explains it. – Andrew Thompson Apr 29 '12 at 19:13

1 Answers1

0

I put the code in the ActionEvent in a seperate method in this listener class, and just invoke that from both the actionPerformed and the focusLost methods instead. Now works fine with a JTextField. I think most people would do that anyway. The actionPerformed code was quite lengthy.