• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFormattedTextField and FocusLost event  RSS feed

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JFormattedTextField set to a SimpleDateFormat ("HH:mm"). When I enter '8:50' and tab out of the field, the field is changed to '08:50' which is what I want. However, the value in the focusLost method of the focus listener returned by getSource().getText() is what was entered '8:50'. Which focus listener method should I be using to get the field after the formatting has been applied? TIA.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I decided I can't accomplish what I need with a focus listener anyway.
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally when one is using JFormattedTextField one would call getValue(), not getText(). However don't expect getValue() to necessarily return a String.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!