title: JXDatePicker using SimpleDateFormat to format dd.MM.yy to dd.MM.yyyy with current century
body: <p>as already explained I want to achieve, that when the user is editing a date within a JXDatePicker, he can choose, weather he types it again in the same format, which is by default dd.MM.yyyy or just dd.MM.yy. When he uses the short form I want the Picker to choose the current century.</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>27.01.2012 edited to 27.01.10 should result in 27.01.2010
  </code></pre>
  
  <p>as well as:</p>
  
  <pre><code>27.01.2012 edited to 27.01.2010 should also result in 27.01.2010
  </code></pre>
  
  <p>By default the JXDatePicker handels it the following way:</p>
  
  <pre><code>27.01.2012 edited to 27.01.10 results in 27.01.0010
  </code></pre>
  
  <p>Which is not really the way I wanted it to work. After some short research I found the following Method in SimpleDateFormat</p>
  
  <pre><code>/**
   * Sets the 100-year period 2-digit years will be interpreted as being in
   * to begin on the date the user specifies.
   *
   * @param startDate During parsing, two digit years will be placed in the range
   * &lt;code&gt;startDate&lt;/code&gt; to &lt;code&gt;startDate + 100 years&lt;/code&gt;.
   */
  public void set2DigitYearStart(Date startDate)
  </code></pre>
  
  <p>On first view this sounded exactly like what I need. So I tested it and unfortunatly it didnt work like I hoped it would. This is because I want to use dd.MM.yyyy as format to display dates and also want it to be displayed like that in editmode. For example when the user klicks on a date like 27.01.2012, I also want it to be like that in editmode, too and not just the short form: 27.01.12.</p>
  
  <p>My Problem now is, that set2DigitYearStart(Date) unfortunatly only works, when I choose to use the shortform in editmode. I made a small example to show this case (SwingX Library is required, because of jxdatepicker and can be found be <a href="http://swinglabs.org/downloads.jsp">here</a>).</p>
  
  <pre><code>public class DatePickerExample extends JPanel
  {
    static JFrame frame;
  
    public DatePickerExample()
    {
      JXDatePicker picker = new JXDatePicker();
      JTextField field = new JTextField( 10 );
  
      add( field );
      add( picker );
  
      final Calendar instance = Calendar.getInstance();
      instance.set( 2012, 01, 26 );
      Date date = instance.getTime();
      picker.setDate( date );
  
      //    SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yy" );//Works, but I wonna display and edit it with dd.MM.yyyy
      SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );
      final Date startDate = new Date( 0 );//01.01.1970
      format.set2DigitYearStart( startDate );
  
      picker.setFormats( format );
    }
  
    public static void main( String[] args )
    {
      frame = new JFrame();
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      frame.setBounds( 400, 400, 400, 400 );
      frame.setLayout( new BorderLayout() );
      frame.add( new DatePickerExample() );
      frame.setVisible( true );
    }
  }
  </code></pre>
  
  <p>Anyone already had the same requirement and can tell me how to make this work? Any ideas are welcome. Thank you very much in advance. ymene</p>