public class DateSelector extends JComponent implements PropertyChangeListener, FocusListener
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected JPopupMenu |
calPopup |
protected JTextField |
dateTF |
protected MiniCal |
minical |
protected boolean |
normalizeYear |
protected JButton |
popupInvoker |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
DateSelector()
Creates a new DateSelector instance comprised of a JTextField and
an selectable icon to the right of the JTextField.
|
DateSelector(boolean showDate)
Creates a new DateSelector instance comprised of a JTextField and
an selectable icon to the right of the JTextField.
|
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(ChangeListener l) |
static Point |
computePopupBounds(int px,
int py,
int pw,
int ph,
Component comp)
Computes the location on the screen for a Popup taking into account
the edges of the screen.
|
void |
focusGained(FocusEvent e)
Invoked when a component gains the keyboard focus.
|
void |
focusLost(FocusEvent e)
Invoked when a component loses the keyboard focus.
|
Color |
getBackground() |
Date |
getDate()
Retrieves the current date represented by this component.
|
String |
getPattern()
Retrieves the date pattern used to render the date into the textfield
|
Color |
getSelectedDateColor()
Retrieves the color representing the user selected date
|
boolean |
getShowPatternTip()
Indicates if the tooltip is displayed or not.
|
String |
getText()
Retrieves the contents of the date textfield.
|
Color |
getTodayColor()
Retrieves the color representing "today"
|
void |
hidePopup()
Provides a way to force the pop-up to hide
|
boolean |
isEditable()
Returns true if component is editable
|
void |
paintComponent(Graphics g) |
void |
propertyChange(PropertyChangeEvent e) |
void |
removeChangeListener(ChangeListener l) |
void |
requestFocus()
Override requestFocus to pass it on to the actual text field
|
void |
setBackground(Color bg) |
void |
setDate(Date d)
Establishes the current date represented by this component
|
void |
setEditable(boolean editable)
Set editability of component
|
void |
setEnabled(boolean b)
Enables/disables the subcomponents that comprise the main component
|
void |
setLayout(LayoutManager lm) |
void |
setPattern(String p) |
void |
setSelectedDateColor(Color c)
Change the color representing the user selected date.
|
void |
setShowPatternTip(boolean b)
Turns on/off the tooltip displaying the current date pattern.
|
void |
setTodayColor(Color c)
Change the color representing "today".
|
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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
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, 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, getAccessibleContext, 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, 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, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected JTextField dateTF
protected JButton popupInvoker
protected JPopupMenu calPopup
protected MiniCal minical
protected boolean normalizeYear
public DateSelector()
public DateSelector(boolean showDate)
showDate
- determines if today's date is displayed in the
textfield initially. If showDate is false, the textfield is initially
blank and the tooltip (containing the date pattern) is turned on.public void hidePopup()
public static Point computePopupBounds(int px, int py, int pw, int ph, Component comp)
px
- : x coordinate - relative to the Component (usually 0)py
- : y coordinate - The height of the control (usually
: comp.getBounds().height)pw
- : width - width of the popup (usually Popup.getSize().width)ph
- : height - height of the popup (usually Popup.getSize().height)comp
- : The component the pop-up belongs to. Like a JTextBox.public void requestFocus()
requestFocus
in class JComponent
public void setLayout(LayoutManager lm)
public Color getBackground()
getBackground
in class Component
public void setBackground(Color bg)
setBackground
in class JComponent
public void addChangeListener(ChangeListener l)
public void removeChangeListener(ChangeListener l)
public void paintComponent(Graphics g)
paintComponent
in class JComponent
public void setShowPatternTip(boolean b)
b
- the flag dictating if the tooltip should be on or offpublic void setEditable(boolean editable)
editable
- New editable flagpublic boolean isEditable()
public boolean getShowPatternTip()
public String getPattern()
public void setPattern(String p)
public String getText()
public Date getDate() throws IllegalArgumentException
IllegalArgumentException
public void setDate(Date d)
d
- the new datepublic void setTodayColor(Color c)
c
- the new today colorpublic Color getTodayColor()
public void setSelectedDateColor(Color c)
c
- the new current date colorpublic Color getSelectedDateColor()
public void setEnabled(boolean b)
setEnabled
in class JComponent
b
- If true, the component is enabled; otherwise it is disabled.public void propertyChange(PropertyChangeEvent e)
propertyChange
in interface PropertyChangeListener
public void focusGained(FocusEvent e)
focusGained
in interface FocusListener
event
- The focus eventpublic void focusLost(FocusEvent e)
focusLost
in interface FocusListener
event
- The focus eventCopyright © 2003, 2023, Oracle and/or its affiliates.