public class JCalendarCombo
extends javax.swing.JComboBox
You may specify a font for each of the elements that make up the pop-up calendar. If you do not specify a font (or specify a null font), a reasonable default will be generated based on the current Look & Feel.
The JCalendarCombo uses a non-mutable ComboBoModel. This means that the following methods will generate an exception:
The combo box listeners work pretty much as for normal combo boxes. The item changed event reports the date "unselected" (the previous date) and "selected" (the new date set), but as Strings. It's probably better to add a DateListener and ignore the ItemListener and ActionListener.
The following key bindings should work (some may depend on the selected Look-and-Feel):
This component tries to adapt it's Look-and-Feel to match the current Look-and-Feel. But it can only do so for Look-and-Feels's that it knows about. To adapt it for new Look-and-Feels, create a sub-class:
public class MyCalendarCombo extends JCalendarCombo {
public void updateUI() {
ComboBoxUI cui = (ComboBoxUI)UIManager.getUI(this);
if (cui instanceof SomeLAFComboBoxUI) {
cui = new SomeLAFCalComboBoxUI();
}
else {
super.updateUI();
}
}
private class SomeLAFCalComboBoxUI extends SomeLAFComboBoxUI {
return new CalendarComboPopup();
}
}
If it can't figure out an appropriate Look-and-Feel, it uses the
Metal Look-and-Feel.Modifier and Type | Class and Description |
---|---|
protected class |
JCalendarCombo.CalendarComboBoxModel |
protected class |
JCalendarCombo.CalendarComboPopup |
javax.swing.JComboBox.AccessibleJComboBox, javax.swing.JComboBox.KeySelectionManager
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
static int |
DISPLAY_DATE
Used to indicate that this component should display the date.
|
static int |
DISPLAY_TIME
Used to indicate that this component should display the time.
|
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
JCalendarCombo()
Create an instance of JCalendarCombo using the default calendar and
locale.
|
JCalendarCombo(java.util.Calendar calendar,
java.util.Locale locale,
int selectedComponents,
boolean isTodayDisplayed)
Create an instance of JCalendarCombo using the given calendar and
locale.
|
JCalendarCombo(java.util.Calendar calendar,
java.util.Locale locale,
int selectedComponents,
boolean isTodayDisplayed,
java.lang.String timePattern)
Create an instance of JCalendarCombo using the given calendar and
locale.
|
JCalendarCombo(int selectedComponents,
boolean isTodayDisplayed)
Create an instance of JCalendarCombo using the default calendar and
locale.
|
Modifier and Type | Method and Description |
---|---|
void |
addDateListener(DateListener listener)
Add a date listener.
|
java.util.Calendar |
getCalendar()
Get a copy of the calendar used by this JCalendar.
|
org.joda.time.DateTime |
getDate()
Get the date currently displayed by the calendar panel.
|
java.text.DateFormat |
getDateFormat()
Get the date format used to display the selected date in the combo
box's text field.
|
java.awt.Font |
getDayFont()
Get the day font.
|
java.awt.Font |
getDayOfWeekFont()
Get the day-of-week font (Mon, Tue, etc.).
|
java.util.Locale |
getLocale()
Return the locale used by this JCalendar.
|
java.awt.Font |
getTimeFont()
Get the time spinner font.
|
java.awt.Font |
getTitleFont()
Get the title font.
|
java.awt.Font |
getTodayFont()
Get the font used to display today's date as text.
|
boolean |
isNullAllowed()
Get whether a null date is allowed.
|
boolean |
isTodayDisplayed()
Returns true if today's date is displayed at the bottom of the
calendar.
|
protected java.lang.String |
paramString() |
void |
removeDateListener(DateListener listener)
Remove a date listener.
|
void |
setDate(org.joda.time.DateTime date)
Set the calendar panel to display the given date.
|
void |
setDateFormat(java.text.DateFormat dateFormat)
Set the date format used to display the selected date in the combo
box's text field.
|
void |
setDateFormatter(org.joda.time.format.DateTimeFormatter dateFormatter) |
void |
setDayFont(java.awt.Font font)
If the font is set to null, then the day font will default to
9/11th's of the L&F's Button default font.
|
void |
setDayOfWeekFont(java.awt.Font font)
If the font is set to null, then the day-of-week font (Mon, Tue,
etc.) will default to 9/11th's of the L&F's Label default font.
|
void |
setKeySelectionManager(javax.swing.JComboBox.KeySelectionManager aManager)
This method is ignored.
|
void |
setNullAllowed(boolean isNullAllowed)
Set whether a null date is allowed.
|
void |
setSelectedItem(java.lang.Object anObject)
Sets the selected item in the combo box display area to the object
in the argument.
|
void |
setTimeFont(java.awt.Font font)
If the font is set to null, then the time spinner font will default
to the L&F's Spinner default font.
|
void |
setTitleFont(java.awt.Font font)
If the font is set to null, then the title font (for the Month Year
title) will default to the L&F's Label default font.
|
void |
setTodayFont(java.awt.Font font)
If the font is set to null, then the font used to display today's
date as text will default to the L&F's Label default font.
|
protected org.joda.time.DateTime |
stringToDate(java.lang.String string)
Given a date in String form, convert it to a Date object.
|
java.lang.String |
toString() |
void |
updateUI()
Resets the UI property to a value from the current look and feel.
|
actionPerformed, actionPropertyChanged, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, processKeyBinding, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setUI, showPopup
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
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, transferFocusDownCycle, validate, validateTree
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, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final int DISPLAY_DATE
public static final int DISPLAY_TIME
public JCalendarCombo()
public JCalendarCombo(int selectedComponents, boolean isTodayDisplayed)
selectedComponents
- Use DISPLAY_DATE, DISPLAY_TIME or
(DISPLAY_DATE | DISPLAY_TIME).isTodayDisplayed
- True if today's date should be displayed.public JCalendarCombo(java.util.Calendar calendar, java.util.Locale locale, int selectedComponents, boolean isTodayDisplayed)
calendar
- The calendar to use.locale
- The locale to use.selectedComponents
- Use DISPLAY_DATE, DISPLAY_TIME or
(DISPLAY_DATE | DISPLAY_TIME).isTodayDisplayed
- True if today's date should be displayed.public JCalendarCombo(java.util.Calendar calendar, java.util.Locale locale, int selectedComponents, boolean isTodayDisplayed, java.lang.String timePattern)
calendar
- The calendar to use.locale
- The locale to use.selectedComponents
- Use DISPLAY_DATE, DISPLAY_TIME or
(DISPLAY_DATE | DISPLAY_TIME).isTodayDisplayed
- True if today's date should be displayed.DateFormat
,
SimpleDateFormat
public java.lang.String toString()
toString
in class java.awt.Component
public void addDateListener(DateListener listener)
listener
- The date listener to add.public void removeDateListener(DateListener listener)
listener
- The date listener to remove.public boolean isNullAllowed()
public void setNullAllowed(boolean isNullAllowed)
If nulls are not allowed, a setDate(null) will be ignored without error. The DELETE key will do nothing.
If you switch from allowing nulls to not allowing nulls and the current date is null, it will remain null until a date is selected.
The component default is to allow nulls.
isNullAllowed
- The whether a null date is allowed.public org.joda.time.DateTime getDate()
getCalendar()
public void setDate(org.joda.time.DateTime date)
date
- The date to set.public java.text.DateFormat getDateFormat()
public void setDateFormat(java.text.DateFormat dateFormat) throws java.lang.NullPointerException
dateFormat
- The date format used to display the selected date
in the combo box's text field.java.lang.NullPointerException
public void setDateFormatter(org.joda.time.format.DateTimeFormatter dateFormatter) throws java.lang.NullPointerException
java.lang.NullPointerException
public java.util.Calendar getCalendar()
getDate()
public java.util.Locale getLocale()
getLocale
in class java.awt.Component
public boolean isTodayDisplayed()
public java.awt.Font getTitleFont()
public void setTitleFont(java.awt.Font font)
Otherwise, the title font is set as given.
font
- The font to set.public java.awt.Font getDayOfWeekFont()
public void setDayOfWeekFont(java.awt.Font font)
Otherwise, the day-of-week font is set as given.
font
- The font to set.public java.awt.Font getDayFont()
public void setDayFont(java.awt.Font font)
Otherwise, the day font is set as given.
font
- The font to set.public java.awt.Font getTimeFont()
public void setTimeFont(java.awt.Font font)
Otherwise, the time spinner font is set as given.
font
- The font to set.public java.awt.Font getTodayFont()
public void setTodayFont(java.awt.Font font)
Otherwise, the font used to display today's date is set as given.
font
- The font to set.public void setSelectedItem(java.lang.Object anObject)
If this constitutes a change in the selected item, ItemListeners added to the combo box will be notified with one or two ItemEvents. If there is a current selected item, an ItemEvent will be fired and the state change will be ItemEvent.DESELECTED. If anObject is in the list and is not currently selected then an ItemEvent will be fired and the state change will be ItemEvent.SELECTED.
ActionListeners added to the combo box will be notified with an ActionEvent when this method is called (assuming the date actually changed).
setSelectedItem
in class javax.swing.JComboBox
anObject
- The object to select.public void setKeySelectionManager(javax.swing.JComboBox.KeySelectionManager aManager)
setKeySelectionManager
in class javax.swing.JComboBox
aManager
- The new key selection manager.public void updateUI()
updateUI
in class javax.swing.JComboBox
protected java.lang.String paramString()
paramString
in class javax.swing.JComboBox
protected org.joda.time.DateTime stringToDate(java.lang.String string)
string
- The date in String form.