• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with selection of text when textfield component gains focus.

 
A Hari Kiran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need your suggestion on how to go ahead with the following thing.

I have a JTextField and I have created a separate class WTextfield which extends the JTextField so that i can set the properties of all the textfields of my project at a single place.

I have implemented Focus listener in the WTextfield so that when ever it gains focus, all the text inside the textfield gets selected.

now when i use this(WTextField) class in my project. i am expecting it to work(selecting the text) when it gains the focus. But nothing is happening.

can anybody tell me why the focusGained method is not getting called. Or what should be done to make it get called.

NOTE: I want to do it at a single place so that it wont be required for me to implement the focus listener every time when my WTextfield is used.

Thanks,
Hari.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you added the focus listener to the JTextField? If so, can you show us the code of the focusGained method?

I've created the following little SSCCE which selects all text when the focus is gained and deselects all text when the focus is lost again:
This code is working just fine for me.
 
A Hari Kiran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Oops...
You hit the bull's eye.
I forgot adding the focus listener..
stupid mistake.
thanks rob.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's often the littlest of mistakes in these cases I once spent half an hour checking my network settings before finding out the network cable was unplugged

And you're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic