Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField highlighted on windows

 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2564
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:

Would this be easier:
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone, it is working perfectly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic