Class ValidatedTextField
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,Scrollable,SwingConstants
Supports two types of validated field: a generic text fields with length and/or character set limited by a Java regular expression or an integral numeric field with minimum and maximum allowed values.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JTextField
JTextField.AccessibleJTextFieldNested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBindingNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Colorstatic final Colorstatic final Colorstatic final Colorstatic final Colorstatic final Color(package private) ValidatedTextFieldstatic final StringFields inherited from class javax.swing.JTextField
notifyActionFields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface 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 -
Constructor Summary
ConstructorsConstructorDescriptionValidatedTextField(Integer len, boolean allow0LengthValue, boolean forceUppercase, Integer minValue, Integer maxValue, String validationRegExpr, String validationErrorMessage) Provides a validated text field, where the validation mechanism requires a String value which passes the matching defined in validationRegExpr, and where the string begins with a number which must be within a specified integral range.ValidatedTextField(Integer len, boolean allow0LengthValue, Integer minValue, Integer maxValue, String validationErrorMessage) Provides a validated text field for integral values, where the validation mechanism requires a numeric value between a minimum and maximum value.ValidatedTextField(Integer len, boolean forceUppercase, String validationRegExpr, String validationErrorMessage) Provides a validated text field, where the validation mechanism requires a String value which passes the matching defined in validationRegExpr .ValidatedTextField(Integer len, int minAcceptableVal, int maxAcceptableVal, String validationErrorMessage) Provide a validated text field, where the validation mechanism requires a Numeric value which is a hexadecimal value which is valid and within a given numeric range. -
Method Summary
Modifier and TypeMethodDescriptionRetrieve the current value of the "Last Queried Value".Retrieve the current "validationRegExp".booleanisValid()Validate the field information.voidSet the color used for the field background when the field value is invalid.voidsetLastQueriedValue(String lastQueriedValue) Set the "Last Queried Value".voidsetValidateRegExp(String validationRegExpr) Set the "validationRegExp".Methods inherited from class javax.swing.JTextField
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffsetMethods inherited from class 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, processInputMethodEvent, 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, writeMethods inherited from class 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, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods 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, transferFocusDownCycle, validate, validateTreeMethods inherited from class 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, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, 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, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
thisone
-
VTF_PC_STAT_LN_UPDATE
- See Also:
-
COLOR_BG_EDITED
-
COLOR_ERROR_VAL
-
COLOR_OK
-
COLOR_BG_OK
-
COLOR_BG_UNEDITED
-
COLOR_BG_ERROR
-
-
Constructor Details
-
ValidatedTextField
public ValidatedTextField(Integer len, boolean forceUppercase, String validationRegExpr, String validationErrorMessage) Provides a validated text field, where the validation mechanism requires a String value which passes the matching defined in validationRegExpr .Validation occurs as part of the process of focus leaving the field. When validation fails, the focus remains within the field, and the field foreground and background colors are changed.
When focus leaves the field and the field value is valid, the value will be checked against the "Last Queried Value". If the current field value matches the "Last Queried Value", the field is colored using the default field foreground and background colors. If instead the current field value does not match the "Last Queried Value", the field background color is changed to reflect that the value is not yet saved. Use the
setLastQueriedValue(String)method to set the value for this comparison.- Parameters:
len- defines the width of the text field entry box, in charactersforceUppercase- determines if all alphabetic characters are forced to uppercasevalidationRegExpr- defines a java regular expression which is used when validating the text input. A string such as "^[0-9]{2}[a-zA-Z]{3,4}$" would require the text field to be a 5 or 6 character string which starts with exactly two digits and followed by either 3 or 4 upper-case or lower-case lettersvalidationErrorMessage- is passed as an argument to the property change listener for the instantiating class
-
ValidatedTextField
public ValidatedTextField(Integer len, boolean allow0LengthValue, boolean forceUppercase, Integer minValue, Integer maxValue, String validationRegExpr, String validationErrorMessage) Provides a validated text field, where the validation mechanism requires a String value which passes the matching defined in validationRegExpr, and where the string begins with a number which must be within a specified integral range.Validation occurs as part of the process of focus leaving the field. When validation fails, the focus remains within the field, and the field foreground and background colors are changed.
When focus leaves the field and the field value is valid, the value will be checked against the "Last Queried Value". If the current field value matches the "Last Queried Value", the field is colorized using the default field foreground and background colors. If instead the current field value does not match the "Last Queried Value", the field background color is changed to reflect that the value is not yet saved. Use the setLastQueriedValue() method to set the value for this comparison.
- Parameters:
len- defines the width of the text field entry box, in characters.allow0LengthValue- determines if a value of 0 characters is allowed as a valid value.forceUppercase- determines if all alphabetic characters are forced to uppercase.minValue- is the smallest allowed value.maxValue- is the largest allowed value.validationRegExpr- defines a java regular expression which is used when validating the text input. A string such as "^[0-9]{2}[a-zA-Z]{3,4}$" would require the text field to be a 5 or 6 character string which starts with exactly two digits and followed by either 3 or 4 upper-case or lower-case letters.validationErrorMessage- is passed as an argument to the property change listener for the instantiating class.
-
ValidatedTextField
public ValidatedTextField(Integer len, boolean allow0LengthValue, Integer minValue, Integer maxValue, String validationErrorMessage) Provides a validated text field for integral values, where the validation mechanism requires a numeric value between a minimum and maximum value.Validation occurs as part of the process of focus leaving the field. When validation fails, the focus remains within the field, and the field foreground and background colors are changed.
When focus leaves the field and the field value is valid, the value will be checked against the "Last Queried Value". If the current field value matches the "Last Queried Value", the field is colored using the default field foreground and background colors. If instead the current field value does not match the "Last Queried Value", the field background color is changed to reflect that the value is not yet saved. Use the setLastQueriedValue() method to set the value for this comparison.
- Parameters:
len- defines the width of the text field entry box, in charactersallow0LengthValue- determines if a value of 0 characters is allowed as a valid valueminValue- is the smallest allowed valuemaxValue- is the largest allowed valuevalidationErrorMessage- is passed as an argument to the property change listener for the instantiating class.
-
ValidatedTextField
public ValidatedTextField(Integer len, int minAcceptableVal, int maxAcceptableVal, String validationErrorMessage) Provide a validated text field, where the validation mechanism requires a Numeric value which is a hexadecimal value which is valid and within a given numeric range.Validation occurs as part of the process of focus leaving the field. When validation fails, the focus remains within the field, and the field foreground and background colors are changed.
When focus leaves the field and the field value is valid, the value will be checked against the "Last Queried Value". If the current field value matches the "Last Queried Value", the field is colored using the default field foreground and background colors. If instead the current field value does not match the "Last Queried Value", the field background color is changed to reflect that the value is not yet saved. Use the
setLastQueriedValue(String)method to set the value for this comparison.- Parameters:
len- the length of the fieldminAcceptableVal- defines the lowest acceptable valuemaxAcceptableVal- defines the lowest acceptable valuevalidationErrorMessage- is passed as an argument to the property change listener for the instantiating class
-
-
Method Details
-
isValid
Validate the field information. Does not make any GUI changes. A field value that is zero-length is considered invalid. -
setLastQueriedValue
Set the "Last Queried Value". This value is used by the colorization process when focus is exiting the field.- Parameters:
lastQueriedValue- the last value verified- See Also:
-
getLastQueriedValue
Retrieve the current value of the "Last Queried Value".- Returns:
- the last value verified
- See Also:
-
setValidateRegExp
Set the "validationRegExp".- Parameters:
validationRegExpr- new validation pattern- See Also:
-
getValidateRegExp
Retrieve the current "validationRegExp". Used in eg. Add Turnout to attach a manager-specific pattern without redrawing the pane- Returns:
- the current validation pattern
- See Also:
-
setInvalidBackgroundColor
Set the color used for the field background when the field value is invalid.- Parameters:
c- background Color to be used when the value is invalid
-