Results 1 to 3 of 3
  1. #1
    User19832 is offline Member
    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:
    Java 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);
       }
    Beginner... stuck on how to use FormattedFields in java for inserting dates-so3em.png

  2. #2
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    106
    Rep Power
    0

    Default Re: Beginner... stuck on how to use FormattedFields in java for inserting dates

    If you can't get the FormattedTextField to work, you could try also using a DocumentFilter and/or an InputVerifier. Or using a JTextField with a DocumentFilter and/or an InputVerifier.

    You can email me at: kaydell@yahoo.com
    Last edited by kaydell2; 02-11-2014 at 08:01 PM.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Beginner... stuck on how to use FormattedFields in java for inserting dates

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Dispaly dates in Java without using Date class
    By dokumar in forum New To Java
    Replies: 3
    Last Post: 11-16-2013, 02:08 AM
  2. Integer Dates to String Dates Problem
    By HelpingIsCaring in forum New To Java
    Replies: 32
    Last Post: 08-23-2013, 01:29 AM
  3. Comparing dates in java
    By Dominic in forum New To Java
    Replies: 4
    Last Post: 11-15-2011, 04:04 PM
  4. using dates in java
    By javapink in forum New To Java
    Replies: 4
    Last Post: 02-10-2011, 08:35 AM
  5. Now stuck with inserting data into a list.
    By mainy in forum New To Java
    Replies: 2
    Last Post: 07-31-2009, 04:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •