• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issue with selection of text when textfield component gains focus.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic