This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

masking dates in text fields  RSS feed

 
Dan Murphy
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using a JFormattedTextField and would like to ensure that users can only enter valid dates in the format "dd/MM/yy". My first attempt at achieving this looks like this:

JFormattedTextField dateField = new JFormattedTextField(MaskFormatter("##/##/##"));

However this doesn't quite work because users can enter (for example) "44/13/07". Is there any support in the JDK for masking date input fields?

Thanks in advance,
Dan
 
Brian Cole
Author
Ranch Hand
Posts: 932
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dan Murphy:
I'm using a JFormattedTextField and would like to ensure that users can only enter valid dates in the format "dd/MM/yy". My first attempt at achieving this looks like this:

JFormattedTextField dateField = new JFormattedTextField(MaskFormatter("##/##/##"));

However this doesn't quite work because users can enter (for example) "44/13/07". Is there any support in the JDK for masking date input fields?


Have you tried

JFormattedTextField dateField = new JFormattedTextField(new DateFormatter(/*...*/));

It was designed for dates, while MaskFormatter wasn't.

It will allow the user to enter something like October 33rd,
but it will change it to November 2nd.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!