Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JTextField for Date input ( DD/MM/YY) or (DD : MM : YY)

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default JTextField for Date input ( DD/MM/YY) or (DD : MM : YY)

    how would it be possible to create a text field where the caret will jump every 2 inserts of text between a character (i.e : or /)
    just like inputting dates 2 digits between those character,

    i really dont know what is that kind of text field is called, so supposedly my question might not that clear

    i tried playing with the JTextField method .getDot() and .getMark() inside a Caretlistener interface, and setting the caret position into a designated index position if the mark or dot is met, but im messing up

    1.) what is that field?, is there an appropriate term for that?
    2.) using the caretlistener, textfield methods determining the position of the caret, would it be possible to do that kind of thing with JTextFields?
    3.) this is my first time encountering the JFormattedTextField class, but i think its better to include the question, is it more possible with that JFormattedTextField than an ordinary JTextField to resolve the issue?


  2. #2
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: JTextField for Date input ( DD/MM/YY) or (DD : MM : YY)

    well my point with the text field is a typing restriction, that when the user typed 2 values it will jump on the second one for another 2 values and jump again on the third one for another 2 values, restricting a continuous input, those values are separated by a character ':' or '\' or '|'

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,261
    Thanks
    176
    Thanked 820 Times in 763 Posts
    Blog Entries
    5

    Default Re: JTextField for Date input ( DD/MM/YY) or (DD : MM : YY)

    How about using 3 JTextFields with a JLabel between each? Tabs will traverse focus between each.

  4. The Following User Says Thank You to copeg For This Useful Post:

    chronoz13 (October 10th, 2011)

  5. #4
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: JTextField for Date input ( DD/MM/YY) or (DD : MM : YY)

    i like the idea, yes i tried, but i was able to resolve the issue by using JFormattedTextField and a MaskFormatter object, to designate the input restriction, thanks anyway

Similar Threads

  1. Replies: 1
    Last Post: July 22nd, 2011, 07:08 AM
  2. same date should entered in another date field
    By shashib09 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: July 14th, 2011, 08:42 AM
  3. drawString and JTextField
    By that_guy in forum AWT / Java Swing
    Replies: 9
    Last Post: January 29th, 2011, 01:43 AM
  4. [SOLVED] allow a new input, dicarding the last mismatch input without terminating the program
    By voltaire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 9th, 2010, 04:44 AM
  5. [SOLVED] JTextField not visible in swing
    By Sterzerkmode in forum AWT / Java Swing
    Replies: 4
    Last Post: May 21st, 2009, 07:37 AM