类 JTextFieldDateEditor

  • 所有已实现的接口:
    java.awt.event.ActionListener, java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CaretListener, javax.swing.Scrollable, javax.swing.SwingConstants, IDateEditor

    public class JTextFieldDateEditor
    extends javax.swing.JFormattedTextField
    implements IDateEditor, javax.swing.event.CaretListener, java.awt.event.FocusListener, java.awt.event.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) $
    作者:
    Kai Toedter
    另请参阅:
    序列化表格
    • 嵌套类概要

      • 从类继承的嵌套类/接口 javax.swing.JFormattedTextField

        javax.swing.JFormattedTextField.AbstractFormatter, javax.swing.JFormattedTextField.AbstractFormatterFactory
      • 从类继承的嵌套类/接口 javax.swing.JTextField

        javax.swing.JTextField.AccessibleJTextField
      • 从类继承的嵌套类/接口 javax.swing.text.JTextComponent

        javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
      • 从类继承的嵌套类/接口 javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • 从类继承的嵌套类/接口 java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • 从类继承的嵌套类/接口 java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • 字段概要

      字段 
      修饰符和类型 字段 说明
      protected java.awt.Color darkGreen  
      protected java.util.Date date  
      protected java.text.SimpleDateFormat dateFormatter  
      protected java.lang.String datePattern  
      protected DateUtil dateUtil  
      protected javax.swing.text.MaskFormatter maskFormatter  
      protected java.lang.String maskPattern  
      protected char placeholder  
      • 从类继承的字段 javax.swing.JFormattedTextField

        COMMIT, COMMIT_OR_REVERT, PERSIST, REVERT
      • 从类继承的字段 javax.swing.JTextField

        notifyAction
      • 从类继承的字段 javax.swing.text.JTextComponent

        DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
      • 从类继承的字段 javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • 从类继承的字段 java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • 从接口继承的字段 java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
      • 从接口继承的字段 javax.swing.SwingConstants

        BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
    • 构造器概要

      构造器 
      构造器 说明
      JTextFieldDateEditor()  
      JTextFieldDateEditor​(boolean showMask, java.lang.String datePattern, java.lang.String maskPattern, char placeholder)  
      JTextFieldDateEditor​(java.lang.String datePattern, java.lang.String maskPattern, char placeholder)  
    • 方法概要

      所有方法 静态方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      void actionPerformed​(java.awt.event.ActionEvent e)
      Validates the typed date and sets it (only if it is valid).
      void caretUpdate​(javax.swing.event.CaretEvent event)
      After any user input, the value of the textfield is proofed.
      java.lang.String createMaskFromDatePattern​(java.lang.String datePattern)
      Creates a mask from a date pattern.
      void focusGained​(java.awt.event.FocusEvent e)  
      void focusLost​(java.awt.event.FocusEvent focusEvent)  
      java.util.Date getDate()
      Returns the date.
      java.lang.String getDateFormatString()
      Returns the date format string.
      java.util.Date getMaxSelectableDate()
      Gets the minimum selectable date.
      java.util.Date getMinSelectableDate()
      Gets the maximum selectable date.
      java.awt.Dimension getPreferredSize()
      Returns the preferred size.
      javax.swing.JComponent getUiComponent()
      Returns the UI component, e.g. the actual JTextField implementing the editor.
      boolean isMaskVisible()
      Returns true, if the mask is visible.
      static void main​(java.lang.String[] s)
      Creates a JFrame with a JCalendar inside and can be used for testing.
      void setDate​(java.util.Date date)
      Sets the date.
      protected void setDate​(java.util.Date date, boolean firePropertyChange)
      Sets the date.
      void setDateFormatString​(java.lang.String dateFormatString)
      Sets the date format string, e.g.
      void setEnabled​(boolean b)
      Enables and disabled the compoment.
      void setLocale​(java.util.Locale locale)
      Sets the locale.
      void setMaskVisible​(boolean isMaskVisible)
      Sets the mask visible.
      void setMaxSelectableDate​(java.util.Date max)
      Sets the maximum selectable date.
      void setMinSelectableDate​(java.util.Date min)
      Sets the minimum selectable date.
      void setSelectableDateRange​(java.util.Date min, java.util.Date max)
      Sets a valid date range for selectable dates.
      • 从类继承的方法 javax.swing.JFormattedTextField

        commitEdit, getActions, getFocusLostBehavior, getFormatter, getFormatterFactory, getUIClassID, getValue, invalidEdit, isEditValid, processFocusEvent, processInputMethodEvent, setDocument, setFocusLostBehavior, setFormatter, setFormatterFactory, setValue
      • 从类继承的方法 javax.swing.JTextField

        actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getScrollOffset, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setFont, setHorizontalAlignment, setScrollOffset
      • 从类继承的方法 javax.swing.text.JTextComponent

        addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, paste, print, print, print, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, viewToModel2D, write
      • 从类继承的方法 javax.swing.JComponent

        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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • 从类继承的方法 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, transferFocusDownCycle, validate, validateTree
      • 从类继承的方法 java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, 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, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, 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, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 字段详细资料

      • date

        protected java.util.Date date
      • dateFormatter

        protected java.text.SimpleDateFormat dateFormatter
      • maskFormatter

        protected javax.swing.text.MaskFormatter maskFormatter
      • datePattern

        protected java.lang.String datePattern
      • maskPattern

        protected java.lang.String maskPattern
      • placeholder

        protected char placeholder
      • darkGreen

        protected java.awt.Color darkGreen
    • 构造器详细资料

      • JTextFieldDateEditor

        public JTextFieldDateEditor()
      • JTextFieldDateEditor

        public JTextFieldDateEditor​(java.lang.String datePattern,
                                    java.lang.String maskPattern,
                                    char placeholder)
      • JTextFieldDateEditor

        public JTextFieldDateEditor​(boolean showMask,
                                    java.lang.String datePattern,
                                    java.lang.String maskPattern,
                                    char placeholder)
    • 方法详细资料

      • getDate

        public java.util.Date getDate()
        从接口复制的说明: IDateEditor
        Returns the date.
        指定者:
        getDate 在接口中 IDateEditor
        返回:
        the date
      • setDate

        public void setDate​(java.util.Date date)
        从接口复制的说明: IDateEditor
        Sets the date. This should be implemented as a bound property, firing the "date" property.
        指定者:
        setDate 在接口中 IDateEditor
        参数:
        date - the date to set
      • setDate

        protected void setDate​(java.util.Date date,
                               boolean firePropertyChange)
        Sets the date.
        参数:
        date - the date
        firePropertyChange - true, if the date property should be fired.
      • setDateFormatString

        public void setDateFormatString​(java.lang.String dateFormatString)
        从接口复制的说明: IDateEditor
        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 在接口中 IDateEditor
        参数:
        dateFormatString - the date format string
      • getDateFormatString

        public java.lang.String getDateFormatString()
        从接口复制的说明: IDateEditor
        Returns the date format string.
        指定者:
        getDateFormatString 在接口中 IDateEditor
        返回:
        the date format string
      • getUiComponent

        public javax.swing.JComponent getUiComponent()
        从接口复制的说明: IDateEditor
        Returns the UI component, e.g. the actual JTextField implementing the editor.
        指定者:
        getUiComponent 在接口中 IDateEditor
        返回:
        the UI component
      • caretUpdate

        public void caretUpdate​(javax.swing.event.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.
        指定者:
        caretUpdate 在接口中 javax.swing.event.CaretListener
        参数:
        event - the caret event
      • focusLost

        public void focusLost​(java.awt.event.FocusEvent focusEvent)
        指定者:
        focusLost 在接口中 java.awt.event.FocusListener
      • focusGained

        public void focusGained​(java.awt.event.FocusEvent e)
        指定者:
        focusGained 在接口中 java.awt.event.FocusListener
      • setLocale

        public void setLocale​(java.util.Locale locale)
        从接口复制的说明: IDateEditor
        Sets the locale. Usually this should have impact on the current date format string.
        指定者:
        setLocale 在接口中 IDateEditor
        覆盖:
        setLocale 在类中 java.awt.Component
        参数:
        locale - the locale to set
      • createMaskFromDatePattern

        public java.lang.String createMaskFromDatePattern​(java.lang.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
        返回:
        the mask
      • isMaskVisible

        public boolean isMaskVisible()
        Returns true, if the mask is visible.
        返回:
        true, if the mask is visible
      • setMaskVisible

        public void setMaskVisible​(boolean isMaskVisible)
        Sets the mask visible.
        参数:
        isMaskVisible - true, if the mask should be visible
      • getPreferredSize

        public java.awt.Dimension getPreferredSize()
        Returns the preferred size. If a date pattern is set, it is the size the date pattern would take.
        覆盖:
        getPreferredSize 在类中 javax.swing.JTextField
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        Validates the typed date and sets it (only if it is valid).
        指定者:
        actionPerformed 在接口中 java.awt.event.ActionListener
      • 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 在接口中 IDateEditor
        覆盖:
        setEnabled 在类中 javax.swing.JComponent
        参数:
        b - true, if the UI component should be enabled.
      • getMaxSelectableDate

        public java.util.Date getMaxSelectableDate()
        从接口复制的说明: IDateEditor
        Gets the minimum selectable date.
        指定者:
        getMaxSelectableDate 在接口中 IDateEditor
        返回:
        the minimum selectable date
      • getMinSelectableDate

        public java.util.Date getMinSelectableDate()
        从接口复制的说明: IDateEditor
        Gets the maximum selectable date.
        指定者:
        getMinSelectableDate 在接口中 IDateEditor
        返回:
        the maximum selectable date
      • setMaxSelectableDate

        public void setMaxSelectableDate​(java.util.Date max)
        从接口复制的说明: IDateEditor
        Sets the maximum selectable date.
        指定者:
        setMaxSelectableDate 在接口中 IDateEditor
        参数:
        max - maximum selectable date
      • setMinSelectableDate

        public void setMinSelectableDate​(java.util.Date min)
        从接口复制的说明: IDateEditor
        Sets the minimum selectable date.
        指定者:
        setMinSelectableDate 在接口中 IDateEditor
        参数:
        min - minimum selectable date
      • setSelectableDateRange

        public void setSelectableDateRange​(java.util.Date min,
                                           java.util.Date max)
        从接口复制的说明: IDateEditor
        Sets a valid date range for selectable dates. If max is before min, the default range with no limitation is set.
        指定者:
        setSelectableDateRange 在接口中 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)
      • main

        public static void main​(java.lang.String[] s)
        Creates a JFrame with a JCalendar inside and can be used for testing.
        参数:
        s - The command line arguments