0

I'd like my dateField to accept two date formats. The solution I currently has only accepts the final element from the String array. Is it possible to accept both date formats?

import java.text.SimpleDateFormat;
import javax.swing.*;

public class TimeConverterView extends JPanel {
private JFormattedTextField dateField;
private final String[] DATE_FORMATS = {"yyy.DDD.HH.mm.ss", "yyyy/MM/dd HH:mm:ss"};

public TimeConverterView() {
    for (String s : DATE_FORMATS){
        dateField = new JFormattedTextField(new SimpleDateFormat(s)); 
    }
} 
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Take a look at [Specifying Formatters and Using Formatter Factories](http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html#factory) – MadProgrammer Apr 03 '13 at 09:52
  • 1
    Get rid of the loop and use a [Composite version of the format](http://stackoverflow.com/a/12124960/1076463) – Robin Apr 03 '13 at 09:59
  • and `yyy.DDD.HH.mm.ss` should be `yyyy.DDD.HH.mm.ss`, then could be works for a standard Java classes without any additional Formatters, use JSpinner as most scallable ...., without a few side effect caused by using plain JFormattedTextField – mKorbel Apr 03 '13 at 10:26
  • 1
    This [example](http://stackoverflow.com/a/2241997/230513) uses `InputVerifier`. – trashgod Apr 03 '13 at 10:50

0 Answers0