20.6 The DateFormatter Class


DateFormatter is a subclass of InternationalFormatter that uses an object of type java.text.DateFormat as its format. JFormattedTextField instantiates a DateFormatter for itself if you pass a java.util.Date or a java.text.DateFormat into its constructor. With a java.util.Date, the format is localized to the default locale. This is usually what you want, but if you want your program to use the same date format no matter where in the world it is run, construct your JFormattedTextField with a specific java.text.DateFormat.

Most of the DateFormatter implementation is concerned with providing support to increment and decrement subfields of any date from the keyboard. It does a nice job with this. If you haven't done so yet, you might want run the SimpleFTF program and play with the date field.

20.6.1 Properties

DateFormatter does not define any properties beyond those it inherits (see Table 20-6). The minimum and maximum properties can be handy if you want the field to be restricted to a specific range of dates.

20.6.2 Constructors

public DateFormatter( )

Create a new DateFormatter and call java.text.DateFormat.getDateInstance( ) to set the format to the formatting style of the current locale.

public DateFormatter(java.text.DateFormat format)

Create a new DateFormatter with the specified format.



Java Swing
Graphic Java 2: Mastering the Jfc, By Geary, 3Rd Edition, Volume 2: Swing
ISBN: 0130796670
EAN: 2147483647
Year: 2001
Pages: 289
Authors: David Geary

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net