• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField automatically highlighting the current values

 
Jenn Terry
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello my mentors,

I want to have JTextField automatically highlighting the current values for overwriting when the box is selected. Is there a way to do this? It seems like something that might occur in an action listener.

Thanks for looking.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want something to happen when you select a component, then adding a FocusListener is the way to go. You'd put that "something" into its focusGained() method.
 
Jenn Terry
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Now I know what to look for. I'll let you know the results when I can get back to it later today.

Much appreciated!
 
Rob Camick
Ranch Hand
Posts: 2701
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to do it for all text fields then you can use the KeyboardFocusManager. See Global Event Listeners for an example.
 
Jenn Terry
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, once I knew what to look for, and figured out how/where to apply, I got it to work! Thank You @Paul and @Rob.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent!

Actually... if you're going to be doing much more Swing programming, you might want to go through the entire Swing tutorial. Or at least (if you didn't already find it) have a look at the Focus Listener tutorial: http://docs.oracle.com/javase/tutorial/uiswing/events/focuslistener.html and at the left there's a long list of listeners which you can use -- I just looked at it and realized I didn't even know there was a mouse-wheel listener.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!