#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    1
    Rep Power
    0

    Question Beginner... stuck on how to use FormattedFields in java for inserting dates


    I know the below code is supposed to format the FormattedTextField but it doesn't seem to do anything to the form (shown in the picture below). I was wanting, when the form loaded: the text field to look something like this

    00/00/2014 - 00:00 am


    Where the user is able to

    - enter datelike information around the symbol separators ( / or : )

    - But where the user could not remove these symbol separators

    Code:

    Code:
      package datefield;
        
        import javax.swing.JFormattedTextField;
        import javax.swing.text.DateFormatter;
        
        
        public class NewJFrame extends javax.swing.JFrame {
            
            public NewJFrame() {
                initComponents();
                formattedTextField();
            }
     
    public void formattedTextField()
       {
            jFormattedTextField1 = new JFormattedTextField(new SimpleDateFormat("MM/dd/yy - mm:HH"));
            jFormattedTextField1.setValue(new Date());
            add(jFormattedTextField1);
       }
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Also posted at: http://www.javaprogrammingforums.com/java-theory-questions/35716-beginner-stuck-how-use-formattedfields-java-inserting-dates.html

IMN logo majestic logo threadwatch logo seochat tools logo