swingx
Version 2005-08-19

org.jdesktop.swingx
Class JXDatePicker

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.jdesktop.swingx.JXDatePicker
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class JXDatePicker
extends JComponent

A component that combines a button, an editable field and a JXMonthView component. The user can select a date from the calendar component, which appears when the button is pressed. The selection from the calendar component will be displayed in editable field. Values may also be modified manually by entering a date into the editable field using one of the supported date formats.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String DATE_IN_MILLIS
           
static String EDITOR
           
static String LINK_PANEL
           
static String MONTH_VIEW
           
static String uiClassID
          UI Class ID
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JXDatePicker()
          Create a new date picker using the current date as the initial selection and the default abstract formatter JXDatePickerFormatter.
JXDatePicker(long millis)
          Create a new date picker using the specified time as the initial selection and the default abstract formatter JXDatePickerFormatter.
 
Method Summary
 void addActionListener(ActionListener l)
          Adds an ActionListener.
 void commitEdit()
          Forces the current value to be taken from the AbstractFormatter and set as the current value.
protected  void fireActionPerformed()
          Fires an ActionEvent to all listeners.
 String getActionCommand()
          Returns the string currently used to identiy fired ActionEvents.
 int getBaseline(int width, int height)
          Get the baseline for the specified component, or a value less than 0 if the baseline can not be determined.
 Date getDate()
          Returns the currently selected date.
 long getDateInMillis()
          Returns the currently selected date in milliseconds.
 JFormattedTextField getEditor()
          Returns the formatted text field used to edit the date selection.
 DateFormat[] getFormats()
          Returns an array of the formats used by the installed formatter if it is a subclass of JXDatePickerFormatter.
 long getLinkDate()
           
 JPanel getLinkPanel()
          Return the panel that is used at the bottom of the popup.
 JXMonthView getMonthView()
          Return the JXMonthView used in the popup to select dates from.
 TimeZone getTimeZone()
          Gets the time zone.
 DatePickerUI getUI()
           
 String getUIClassID()
           
 boolean isEditable()
           
 boolean isEditValid()
          Returns true if the current value being edited is valid.
 void postActionEvent()
           
 void removeActionListener(ActionListener l)
          Removes an ActionListener.
 void setActionCommand(String actionCommand)
          Sets the string used to identify fired ActionEvents.
 void setComponentOrientation(ComponentOrientation orientation)
           
 void setDate(Date date)
          Set the currently selected date.
 void setDateInMillis(long millis)
          Set the currently selected date.
 void setEditable(boolean value)
           
 void setEditor(JFormattedTextField editor)
           
 void setFormats(DateFormat[] formats)
          Replaces the currently installed formatter and factory used by the editor.
 void setFormats(String[] formats)
          Replaces the currently installed formatter and factory used by the editor.
 void setLinkDate(long linkDate, String linkFormatString)
          Set the date the link will use and the string defining a MessageFormat to format the link.
 void setLinkPanel(JPanel linkPanel)
          Set the panel that will be used at the bottom of the popup.
 void setMonthView(JXMonthView monthView)
          Set the component to use the specified JXMonthView.
 void setTimeZone(TimeZone tz)
          Sets the time zone with the given time zone value.
 void setUI(DatePickerUI ui)
          Sets the L&F object that renders this component.
 void updateUI()
          Resets the UI property with the value from the current look and feel.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uiClassID

public static final String uiClassID
UI Class ID

See Also:
Constant Field Values

EDITOR

public static final String EDITOR
See Also:
Constant Field Values

MONTH_VIEW

public static final String MONTH_VIEW
See Also:
Constant Field Values

DATE_IN_MILLIS

public static final String DATE_IN_MILLIS
See Also:
Constant Field Values

LINK_PANEL

public static final String LINK_PANEL
See Also:
Constant Field Values
Constructor Detail

JXDatePicker

public JXDatePicker()
Create a new date picker using the current date as the initial selection and the default abstract formatter JXDatePickerFormatter. The date picker is configured with the default time zone and locale

See Also:
setTimeZone(java.util.TimeZone), getTimeZone()

JXDatePicker

public JXDatePicker(long millis)
Create a new date picker using the specified time as the initial selection and the default abstract formatter JXDatePickerFormatter. The date picker is configured with the default time zone and locale

Parameters:
millis - initial time in milliseconds
See Also:
setTimeZone(java.util.TimeZone), getTimeZone()
Method Detail

getUI

public DatePickerUI getUI()

setUI

public void setUI(DatePickerUI ui)
Sets the L&F object that renders this component.

Parameters:
ui -

updateUI

public void updateUI()
Resets the UI property with the value from the current look and feel.

Overrides:
updateUI in class JComponent
See Also:
UIManager.getUI(javax.swing.JComponent)

getUIClassID

public String getUIClassID()
Overrides:
getUIClassID in class JComponent

setFormats

public void setFormats(String[] formats)
Replaces the currently installed formatter and factory used by the editor. These string formats are defined by the java.text.SimpleDateFormat class.

Parameters:
formats - The string formats to use.
See Also:
SimpleDateFormat

setFormats

public void setFormats(DateFormat[] formats)
Replaces the currently installed formatter and factory used by the editor.

Parameters:
formats - The date formats to use.

getFormats

public DateFormat[] getFormats()
Returns an array of the formats used by the installed formatter if it is a subclass of JXDatePickerFormatter. javax.swing.JFormattedTextField.AbstractFormatter and javax.swing.text.DefaultFormatter do not have support for accessing the formats used.

Returns:
array of formats or null if unavailable.

setDate

public void setDate(Date date)
Set the currently selected date.

Parameters:
date - date

setDateInMillis

public void setDateInMillis(long millis)
Set the currently selected date.

Parameters:
millis - milliseconds

getDate

public Date getDate()
Returns the currently selected date.

Returns:
Date

getDateInMillis

public long getDateInMillis()
Returns the currently selected date in milliseconds.

Returns:
the date in milliseconds

getMonthView

public JXMonthView getMonthView()
Return the JXMonthView used in the popup to select dates from.

Returns:
the month view component

setMonthView

public void setMonthView(JXMonthView monthView)
Set the component to use the specified JXMonthView. If the new JXMonthView is configured to a different time zone it will affect the time zone of this component.

Parameters:
monthView - month view comopnent
See Also:
setTimeZone(java.util.TimeZone), getTimeZone()

getTimeZone

public TimeZone getTimeZone()
Gets the time zone. This is a convenience method which returns the time zone of the JXMonthView being used.

Returns:
The TimeZone used by the JXMonthView.

setTimeZone

public void setTimeZone(TimeZone tz)
Sets the time zone with the given time zone value. This is a convenience method which returns the time zone of the JXMonthView being used.

Parameters:
tz - The TimeZone.

getLinkDate

public long getLinkDate()

setLinkDate

public void setLinkDate(long linkDate,
                        String linkFormatString)
Set the date the link will use and the string defining a MessageFormat to format the link. If no valid date is in the editor when the popup is displayed the popup will focus on the month the linkDate is in. Calling this method will replace the currently installed linkPanel and install a new one with the requested date and format.

Parameters:
linkDate - Date in milliseconds
linkFormatString - String used to format the link
See Also:
MessageFormat

getLinkPanel

public JPanel getLinkPanel()
Return the panel that is used at the bottom of the popup. The default implementation shows a link that displays the current month.

Returns:
The currently installed link panel

setLinkPanel

public void setLinkPanel(JPanel linkPanel)
Set the panel that will be used at the bottom of the popup.

Parameters:
linkPanel - The new panel to install in the popup

getEditor

public JFormattedTextField getEditor()
Returns the formatted text field used to edit the date selection.

Returns:
the formatted text field

setEditor

public void setEditor(JFormattedTextField editor)

setComponentOrientation

public void setComponentOrientation(ComponentOrientation orientation)
Overrides:
setComponentOrientation in class Component

isEditValid

public boolean isEditValid()
Returns true if the current value being edited is valid.

Returns:
true if the current value being edited is valid.

commitEdit

public void commitEdit()
                throws ParseException
Forces the current value to be taken from the AbstractFormatter and set as the current value. This has no effect if there is no current AbstractFormatter installed.

Throws:
ParseException

setEditable

public void setEditable(boolean value)

isEditable

public boolean isEditable()

getBaseline

public int getBaseline(int width,
                       int height)
Get the baseline for the specified component, or a value less than 0 if the baseline can not be determined. The baseline is measured from the top of the component.

Parameters:
width - Width of the component to determine baseline for.
height - Height of the component to determine baseline for.
Returns:
baseline for the specified component

getActionCommand

public String getActionCommand()
Returns the string currently used to identiy fired ActionEvents.

Returns:
String The string used for identifying ActionEvents.

setActionCommand

public void setActionCommand(String actionCommand)
Sets the string used to identify fired ActionEvents.

Parameters:
actionCommand - The string used for identifying ActionEvents.

addActionListener

public void addActionListener(ActionListener l)
Adds an ActionListener.

The ActionListener will receive an ActionEvent when a selection has been made.

Parameters:
l - The ActionListener that is to be notified

removeActionListener

public void removeActionListener(ActionListener l)
Removes an ActionListener.

Parameters:
l - The action listener to remove.

fireActionPerformed

protected void fireActionPerformed()
Fires an ActionEvent to all listeners.


postActionEvent

public void postActionEvent()

swingx
Version 2005-08-19