• Post Reply Bookmark Topic Watch Topic
  • New Topic

Developing JTextField which accepts only date  RSS feed

 
Anand Kaimal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Component extended JTextField and set it's document as a PlainDocument.
I need to diaplay a built-in mask like "XX/XX/XXXX" in a JTexField, meaning that the user will SKIP the seperators ("/") and will be able to enter characters only in the X positions.
The skips must occur even if the user is inserting or just navigation within the JTextField (left and right).
could anyone please assist me with any solution of how to implement that without the need to seperate it into 3 different components?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you put a KeyEvent Listener on the JTextField and count the keystrokes, you can slip in the formats as the user types and wipe out the slashes or dashes if the user puts them in.
 
Anand Kaimal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ! Actually we developed the component which is a sub class of plain document and it works perfectly.
Anand.
Originally posted by Cindy Glass:
If you put a KeyEvent Listener on the JTextField and count the keystrokes, you can slip in the formats as the user types and wipe out the slashes or dashes if the user puts them in.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!