Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FocusListener on custom JTextField  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a custom class (SKTextField) which extends JTextField, and
has its own model extending PlainDocument. I want to add a focus listener to this custom text field so whenever focus is gained, all of the text in it is selected. I created an inner class in the custom text field class extending FocusAdapter using the focusGained() event. In the focusGained method I am calling the method selectAll().
Then in the constructor of the custom text field class, I am adding the focus listener to the text field, however I can't seem to get the event to fire at all. Can anyone please tell me what I am doing wrong?
Thanks!
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems to work okay with J2SE 1.4.2
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I tried adding this FocusListener again, and now it works. I copied the code for your FocusListener into my app and it works. The only difference I could see, was before, I had declared the FocusListener class as private rather than using default.

Thanks again!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!