bill.util.gui
Class JTextFieldMaxChars
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.text.JTextComponent
|
+--javax.swing.JTextField
|
+--bill.util.gui.JTextFieldMaxChars
- All Implemented Interfaces:
- Accessible, ImageObserver, MenuContainer, Scrollable, Serializable, SwingConstants
- Direct Known Subclasses:
- JTextFieldEnter, JTextFieldFilter
- public class JTextFieldMaxChars
- extends JTextField
This is special implementation of the JTextField class that restricts the
number of characters the user can enter into the text field.
- See Also:
- Serialized Form
Field Summary |
protected int |
_maxChars
The maximum number of characters to allow the user to enter in the text
field. |
protected boolean |
_shiftFocusWhenFull
Indicates if focus should shift to the next component when this one
has had the maximum number of characters entered in it. |
Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NORTH, NORTH_EAST, NORTH_WEST, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Constructor Summary |
JTextFieldMaxChars()
Constructs a new JTextFieldMaxChars. |
JTextFieldMaxChars(int columns)
Constructs a new empty TextFieldMaxChars with the specified number
of columns. |
JTextFieldMaxChars(int columns,
int maxChars)
Constructs a new empty TextFieldMaxChars with the specified number
of columns. |
JTextFieldMaxChars(int maxChars,
String text)
Constructs a new TextFieldMaxChars initialized with the specified
text and maximum number of allowed characters. |
JTextFieldMaxChars(String text)
Constructs a new TextFieldMaxChars initialized with the specified
text. |
JTextFieldMaxChars(String text,
int columns)
Constructs a new JTextFieldMaxChars initialized with the specified text
and columns. |
JTextFieldMaxChars(String text,
int columns,
int maxChars)
Constructs a new JTextFieldMaxChars initialized with the specified text,
columns, and maximum number of allowed characters. |
Method Summary |
protected Document |
createDefaultModel()
We override the regular createDefaultModel in order to enforce the
use of our special filtering document model. |
protected JTextFieldMaxCharsDocument |
getJTextFieldDocument()
Retrieves the special document associated with this text field. |
int |
getMaxChars()
Gets the maximum number of characters that a use may enter in a text
field. |
boolean |
isShiftFocusWhenFull()
Checks if the focus should change to the next component when this text
field has reached it's maximum number of characters. |
void |
setMaxChars(int maxChars)
Sets the maximum number of characters that a use may enter in a text
field. |
void |
setShiftFocusWhenFull(boolean shift)
Sets the shift focus indicator. |
Methods inherited from class javax.swing.JTextField |
addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireActionPerformed, getAccessibleContext, getAction, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setFont, setHorizontalAlignment, setScrollOffset |
Methods inherited from class javax.swing.text.JTextComponent |
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretPosition, getDisabledTextColor, getDocument, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getUI, isEditable, isFocusTraversable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setDocument, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, write |
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, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, 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, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus |
_maxChars
protected int _maxChars
- The maximum number of characters to allow the user to enter in the text
field.
_shiftFocusWhenFull
protected boolean _shiftFocusWhenFull
- Indicates if focus should shift to the next component when this one
has had the maximum number of characters entered in it. Defaults to
false
.
JTextFieldMaxChars
public JTextFieldMaxChars()
- Constructs a new JTextFieldMaxChars. A default model is created, the
initial string is null, and the number of columns is set to 0.
JTextFieldMaxChars
public JTextFieldMaxChars(int columns)
- Constructs a new empty TextFieldMaxChars with the specified number
of columns. A default model is created and the initial string is set
to
null
.
- Parameters:
columns
- the number of columns to use to calculate the preferred
width. If columns is set to zero, the preferred width will be whatever
naturally results from the component implementation.
JTextFieldMaxChars
public JTextFieldMaxChars(int columns,
int maxChars)
- Constructs a new empty TextFieldMaxChars with the specified number
of columns. A default model is created and the initial string is set
to
null
.
- Parameters:
columns
- the number of columns to use to calculate the preferred
width. If columns is set to zero, the preferred width will be whatever
naturally results from the component implementation.maxChars
- The maximum number of characters to allow in the text
field.
JTextFieldMaxChars
public JTextFieldMaxChars(String text)
- Constructs a new TextFieldMaxChars initialized with the specified
text. A default model is created and the number of columns is 0.
- Parameters:
text
- The text to be displayed, or null
.
JTextFieldMaxChars
public JTextFieldMaxChars(int maxChars,
String text)
- Constructs a new TextFieldMaxChars initialized with the specified
text and maximum number of allowed characters. A default model is
created and the number of columns is 0. Ideally the maximum number of
characters would be the last parameter, but that would conflict with
an existing creator.
- Parameters:
maxChars
- The maximum number of characters to allow in the text
field.text
- The text to be displayed, or null
.
JTextFieldMaxChars
public JTextFieldMaxChars(String text,
int columns)
- Constructs a new JTextFieldMaxChars initialized with the specified text
and columns. A default model is created.
- Parameters:
text
- The text to be displayed, or null
.columns
- The number of columns to use to calculate the preferred
width. If columns is set to zero, the preferred width will be whatever
naturally results from the component implementation.
JTextFieldMaxChars
public JTextFieldMaxChars(String text,
int columns,
int maxChars)
- Constructs a new JTextFieldMaxChars initialized with the specified text,
columns, and maximum number of allowed characters. A default model is
created.
- Parameters:
text
- The text to be displayed, or null
.columns
- The number of columns to use to calculate the preferred
width. If columns is set to zero, the preferred width will be whatever
naturally results from the component implementation.maxChars
- The maximum number of characters to allow in the text
field.
setMaxChars
public void setMaxChars(int maxChars)
- Sets the maximum number of characters that a use may enter in a text
field.
- Parameters:
maxChars
- The maximum number of characters.
getMaxChars
public int getMaxChars()
- Gets the maximum number of characters that a use may enter in a text
field.
- Returns:
- The maximum number of characters.
setShiftFocusWhenFull
public void setShiftFocusWhenFull(boolean shift)
- Sets the shift focus indicator. This indicates if the focus should change
to the next component when this text field has reached it's maximum
number of characters. A value of
true
indicates to shift
focus.
- Parameters:
shift
- Value of true
indicates to shift focus, value
of false
indicates not to.
isShiftFocusWhenFull
public boolean isShiftFocusWhenFull()
- Checks if the focus should change to the next component when this text
field has reached it's maximum number of characters. A value of
true
indicates to shift focus.
- Returns:
- If shift is on, returns
true
, otherwise returns
false
.
getJTextFieldDocument
protected JTextFieldMaxCharsDocument getJTextFieldDocument()
- Retrieves the special document associated with this text field.
- Returns:
- The associated document.
createDefaultModel
protected Document createDefaultModel()
- We override the regular createDefaultModel in order to enforce the
use of our special filtering document model.
- Overrides:
createDefaultModel
in class JTextField
- Returns:
- A new filtering document model.