Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8034818

JFormattedTextField does not accept DateTimeFormatter as formatter

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8
    • client-libs

      A DESCRIPTION OF THE REQUEST :
      The new datetime api really works much better than the previous. Even at a connection to the jdbc interface was intended. Unfortunately, the api can not be used by some of the swing components. For example, the new DateTimeFormatter is not yet accepted by the JFormattedTextField. An extension of the component would certainly be helpful.

      JUSTIFICATION :
      If you refactor your application or write a new one only using the new date and time api (JSR-310), you also have to consider your human interaction interface (i.e. your swing components).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      JFormattedTextField accepts DateTimeFormatter as input in one of its Constructors and uses it as formatter for the input.
      ACTUAL -
      There is no support for the new DateTimeFormatter in JFormattedTextFields.

      ---------- BEGIN SOURCE ----------
      DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
      JFormattedTextField tf = new JFormattedTextField(formatter);
      System.out.println(tf.getText());
      tf.setText(formatter.format(LocalDate.now()));
      LocalDate date = (LocalDate) tf.getValue();
      System.out.println(date);

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use the old Formatters and date time classes in JFormattedTextFields and convert the Date objects to LocalDates.
      Use JTextfield with an InputVerifier that uses the new DateTimeFormatter to verify the input.

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: