com.toedter.calendar
Class JDateChooser

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bycom.toedter.calendar.JDateChooser
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, javax.swing.event.ChangeListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.PropertyChangeListener, java.io.Serializable

public class JDateChooser
extends javax.swing.JPanel
implements java.awt.event.ActionListener, java.beans.PropertyChangeListener, javax.swing.event.ChangeListener

A date chooser containig a date spinner and a button, that makes a JCalendar visible for choosing a date.

Version:
1.2.2
Author:
Kai Toedter
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  javax.swing.JButton calendarButton
           
protected  java.lang.String dateFormatString
           
protected  boolean dateSelected
           
protected  javax.swing.JSpinner dateSpinner
           
protected  javax.swing.JSpinner.DateEditor editor
           
protected  boolean isInitialized
           
protected  JCalendar jcalendar
           
protected  java.util.Date lastSelectedDate
           
protected  javax.swing.SpinnerDateModel model
           
protected  javax.swing.JPopupMenu popup
           
protected  boolean startEmpty
           
 
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
JDateChooser()
          Creates a new JDateChooser object.
JDateChooser(boolean startEmpty)
          Creates a new JDateChooser object.
JDateChooser(javax.swing.ImageIcon icon)
          Creates a new JDateChooser object.
JDateChooser(JCalendar jcalendar)
          Creates a new JDateChooser object from a given JCalendar.
JDateChooser(JCalendar jcalendar, java.lang.String dateFormatString, boolean startEmpty, javax.swing.ImageIcon icon)
          Creates a new JDateChooser.
JDateChooser(java.lang.String dateFormatString, boolean startEmpty)
          Creates a new JDateChooser object with given date format string.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Called when the jalendar button was pressed.
 java.util.Date getDate()
          Returns the date.
 java.lang.String getDateFormatString()
          Gets the date format string.
 javax.swing.SpinnerDateModel getModel()
          Return the SpinnerDateModel associated with this control.
 java.lang.String getName()
          Returns "JDateChooser".
 javax.swing.JSpinner getSpinner()
          Return this controls JSpinner control.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Listens for a "date" property change or a "day" property change event from the JCalendar.
 void setDate(java.util.Date date)
          Sets the date.
 void setDateFormatString(java.lang.String dateFormatString)
          Sets the date format string.
 void setLocale(java.util.Locale l)
          Sets the locale.
 void setModel(javax.swing.SpinnerDateModel mdl)
          Set the SpinnerDateModel for this control.
 void stateChanged(javax.swing.event.ChangeEvent e)
          Fires property "date" changes, recting on the spinner's state changes.
 void updateUI()
          Updates the UI of itself and the popup.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, 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

calendarButton

protected javax.swing.JButton calendarButton

dateSpinner

protected javax.swing.JSpinner dateSpinner

editor

protected javax.swing.JSpinner.DateEditor editor

jcalendar

protected JCalendar jcalendar

popup

protected javax.swing.JPopupMenu popup

model

protected javax.swing.SpinnerDateModel model

dateFormatString

protected java.lang.String dateFormatString

dateSelected

protected boolean dateSelected

isInitialized

protected boolean isInitialized

lastSelectedDate

protected java.util.Date lastSelectedDate

startEmpty

protected boolean startEmpty
Constructor Detail

JDateChooser

public JDateChooser()
Creates a new JDateChooser object.


JDateChooser

public JDateChooser(javax.swing.ImageIcon icon)
Creates a new JDateChooser object.

Parameters:
icon - the new icon

JDateChooser

public JDateChooser(boolean startEmpty)
Creates a new JDateChooser object.

Parameters:
startEmpty - true, if the date field should be empty

JDateChooser

public JDateChooser(java.lang.String dateFormatString,
                    boolean startEmpty)
Creates a new JDateChooser object with given date format string. The default date format string is "MMMMM d, yyyy".

Parameters:
dateFormatString - the date format string
startEmpty - true, if the date field should be empty

JDateChooser

public JDateChooser(JCalendar jcalendar)
Creates a new JDateChooser object from a given JCalendar.

Parameters:
jcalendar - the JCalendar

JDateChooser

public JDateChooser(JCalendar jcalendar,
                    java.lang.String dateFormatString,
                    boolean startEmpty,
                    javax.swing.ImageIcon icon)
Creates a new JDateChooser.

Parameters:
jcalendar - the jcalendar or null
dateFormatString - the date format string or null (then "MMMMM d, yyyy" is used)
startEmpty - true, if the date field should be empty
icon - the icon or null (then an internal icon is used)
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Called when the jalendar button was pressed.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the action event

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Listens for a "date" property change or a "day" property change event from the JCalendar. Updates the dateSpinner and closes the popup.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
evt - the event

updateUI

public void updateUI()
Updates the UI of itself and the popup.


setLocale

public void setLocale(java.util.Locale l)
Sets the locale.

Parameters:
l - The new locale value

getDateFormatString

public java.lang.String getDateFormatString()
Gets the date format string.

Returns:
Returns the dateFormatString.

setDateFormatString

public void setDateFormatString(java.lang.String dateFormatString)
Sets the date format string. E.g "MMMMM d, yyyy" will result in "July 21, 2004" if this is the selected date and locale is English.

Parameters:
dateFormatString - The dateFormatString to set.

getName

public java.lang.String getName()
Returns "JDateChooser".

Returns:
the name value

getDate

public java.util.Date getDate()
Returns the date.

Returns:
the current date

setDate

public void setDate(java.util.Date date)
Sets the date. Fires the property change "date".

Parameters:
date - the new date.

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Fires property "date" changes, recting on the spinner's state changes.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener
Parameters:
e - the change event

getSpinner

public javax.swing.JSpinner getSpinner()
Return this controls JSpinner control.

Returns:
the JSpinner control

getModel

public javax.swing.SpinnerDateModel getModel()
Return the SpinnerDateModel associated with this control.

Returns:
the SpinnerDateModel

setModel

public void setModel(javax.swing.SpinnerDateModel mdl)
Set the SpinnerDateModel for this control. This method allows the JDateChooser control to be used with some persistence frameworks (ie. Oracle ADF) to bind the control to the database Date value.

Parameters:
mdl - the SpinnerDateModel


Copyright © 1999 - 2004 Kai Toedter.