aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Issue with selection of text when textfield component gains focus. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Issue with selection of text when textfield component gains focus. " Watch "Issue with selection of text when textfield component gains focus. " New topic
Author

Issue with selection of text when textfield component gains focus.

A Hari Kiran
Greenhorn

Joined: Jul 28, 2009
Posts: 5
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

Joined: Oct 27, 2005
Posts: 19760
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
A Hari Kiran
Greenhorn

Joined: Jul 28, 2009
Posts: 5

Oops...
You hit the bull's eye.
I forgot adding the focus listener..
stupid mistake.
thanks rob.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with selection of text when textfield component gains focus.