Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
  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);
   }



Screenshot:

<img src="http://i.stack.imgur.com/sO3em.png">
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900