Class FormatStringConverter<T>

java.lang.Object
javafx.util.StringConverter<T>
javafx.util.converter.FormatStringConverter<T>
Type Parameters:
T - the type converted to/from a string

public class FormatStringConverter<T> extends StringConverter<T>
A StringConverter implementation that can use a Format instance to convert arbitrary types to and from a string. Instances of this class are only immutable if the used Format is immutable.
Since:
JavaFX 2.2
  • Constructor Details

    • FormatStringConverter

      public FormatStringConverter(Format format)
      Creates a FormatStringConverter for arbitrary types that uses the given Format.
      Parameters:
      format - the formatter/parser that will be used by the toString() and fromString() methods. Must not be null.
  • Method Details

    • getFormat

      protected Format getFormat()
      Returns the Format instance for formatting and parsing in this FormatStringConverter.
      Returns:
      the Format instance for formatting and parsing in this FormatStringConverter
    • fromString

      public T fromString(String string)
      Converts a string to an object. The parsing mechanism is defined by the specific converter. null and empty string are converted to null.
      Specified by:
      fromString in class StringConverter<T>
      Parameters:
      string - the String to convert
      Returns:
      an object of type T created from the string passed in
    • toString

      public String toString(T object)
      Converts an object to a string form. The format of the returned string is defined by the specific converter. null is converted to an empty string, otherwise the type's toString is used.
      Specified by:
      toString in class StringConverter<T>
      Parameters:
      object - the object of type T to convert
      Returns:
      a string representation of the object passed in