com.toedter.calendar
Class JTextFieldDateEditor
JFormattedTextField
com.toedter.calendar.JTextFieldDateEditor
- ActionListener, CaretListener, FocusListener, IDateEditor
public class JTextFieldDateEditor
extends JFormattedTextField
implements IDateEditor, CaretListener, FocusListener, ActionListener
JTextFieldDateEditor is the default editor used by JDateChooser. It is a
formatted text field, that colores valid dates green/black and invalid dates
red. The date format patten and mask can be set manually. If not set, the
MEDIUM pattern of a SimpleDateFormat with regards to the actual locale is
used.
$LastChangedRevision: 97 $, $LastChangedDate: 2006-05-24 17:30:41 +0200 (Mi, 24 Mai 2006) $
darkGreen
protected Color darkGreen
dateFormatter
protected SimpleDateFormat dateFormatter
datePattern
protected String datePattern
maskFormatter
protected MaskFormatter maskFormatter
maskPattern
protected String maskPattern
placeholder
protected char placeholder
JTextFieldDateEditor
public JTextFieldDateEditor()
JTextFieldDateEditor
public JTextFieldDateEditor(String datePattern,
String maskPattern,
char placeholder)
JTextFieldDateEditor
public JTextFieldDateEditor(boolean showMask,
String datePattern,
String maskPattern,
char placeholder)
actionPerformed
public void actionPerformed(ActionEvent e)
Validates the typed date and sets it (only if it is valid).
caretUpdate
public void caretUpdate(CaretEvent event)
After any user input, the value of the textfield is proofed. Depending on
being a valid date, the value is colored green or red.
createMaskFromDatePattern
public String createMaskFromDatePattern(String datePattern)
Creates a mask from a date pattern. This is a very simple (and
incomplete) implementation thet works only with numbers. A date pattern
of "MM/dd/yy" will result in the mask "##/##/##". Probably you want to
override this method if it does not fit your needs.
datePattern
- the date pattern
focusGained
public void focusGained(FocusEvent e)
focusLost
public void focusLost(FocusEvent focusEvent)
getMaxSelectableDate
public Date getMaxSelectableDate()
Gets the minimum selectable date.
- getMaxSelectableDate in interface IDateEditor
- the minimum selectable date
getMinSelectableDate
public Date getMinSelectableDate()
Gets the maximum selectable date.
- getMinSelectableDate in interface IDateEditor
- the maximum selectable date
getPreferredSize
public Dimension getPreferredSize()
Returns the preferred size. If a date pattern is set, it is the size the
date pattern would take.
getUiComponent
public JComponent getUiComponent()
Returns the UI component, e.g. the actual JTextField implementing the
editor.
- getUiComponent in interface IDateEditor
isMaskVisible
public boolean isMaskVisible()
Returns true, if the mask is visible.
- true, if the mask is visible
main
public static void main(String[] s)
Creates a JFrame with a JCalendar inside and can be used for testing.
s
- The command line arguments
setDate
public void setDate(Date date)
Sets the date. This should be implemented as a bound property, firing the
"date" property.
- setDate in interface IDateEditor
setDate
protected void setDate(Date date,
boolean firePropertyChange)
Sets the date.
date
- the datefirePropertyChange
- true, if the date property should be fired.
setDateFormatString
public void setDateFormatString(String dateFormatString)
Sets the date format string, e.g. "MM/dd/yy". If the date format string
is null or invalid, the date format string will be set to the MEDIUM
Simple date format of the current locale.
- setDateFormatString in interface IDateEditor
dateFormatString
- the date format string
setEnabled
public void setEnabled(boolean b)
Enables and disabled the compoment. It also fixes the background bug
4991597 and sets the background explicitely to a
TextField.inactiveBackground.
- setEnabled in interface IDateEditor
setLocale
public void setLocale(Locale locale)
Sets the locale. Usually this should have impact on the current date
format string.
- setLocale in interface IDateEditor
locale
- the locale to set
setMaskVisible
public void setMaskVisible(boolean isMaskVisible)
Sets the mask visible.
isMaskVisible
- true, if the mask should be visible
setMaxSelectableDate
public void setMaxSelectableDate(Date max)
Sets the maximum selectable date.
- setMaxSelectableDate in interface IDateEditor
max
- maximum selectable date
setMinSelectableDate
public void setMinSelectableDate(Date min)
Sets the minimum selectable date.
- setMinSelectableDate in interface IDateEditor
min
- minimum selectable date
setSelectableDateRange
public void setSelectableDateRange(Date min,
Date max)
Sets a valid date range for selectable dates. If max is before
min, the default range with no limitation is set.
- setSelectableDateRange in interface IDateEditor
min
- the minimum selectable date or null (then the minimum date should be
set to 01\01\0001)max
- the maximum selectable date or null (then the maximum date should be
set to 01\01\9999)
Copyright B) 1999 - 2006 Kai Toedter.