This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes JTextField highlighted on windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField highlighted on windows " Watch "JTextField highlighted on windows " New topic
Author

JTextField highlighted on windows

Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
    
    2
On my program I am setting the UIManager to CrossPlatformLookAndFeel. I am running the program on both a Mac and Windows. On the mac as I tab through my JTextFields the text is highlighted and the default text is erased when the user begans typing. On the Windows system the text is not highlighted and the cursor appears at the end of the default text. I would like the Windows system to highlight the text also, I assume I need to change the a property on the UIDefaults, is that correct and which value needs to be changed.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Can't find anything in UIDefaults. However, long time back, when I wanted the same behavior on Windoze, I had added subclassed JTextField, added a focus listener, and on focus gained, selected the existing text.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if you have multiple textfields, perhaps a global focus listener might suit



and if you want the caret position at the beginning, change this

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2177
    
    7
If you only want this behaviour for specific text fields then you would use the FocusListener approach as suggested by Maneesh.

If you want this on all text fields, then I would use a KeyboardFocusManager. The example found in Global Event Listeners will work for formatted text fields as well.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Michael Dunn wrote:

Would this be easier:
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
    
    2
Thank you everyone, it is working perfectly
 
Don't get me started about those stupid light bulbs.
 
subject: JTextField highlighted on windows