public class JFormattedTextField extends JTextField
JFormattedTextField.AbstractFormatterFactory. This factory is responsible for providing
an instance of JFormattedTextField.AbstractFormatter that is able to handle the
formatting of the value of the JFormattedTextField.| Modifier and Type | Class and Description |
|---|---|
static class |
JFormattedTextField.AbstractFormatter
An abstract base implementation for a formatter that can be used by
a JTextField.
|
static class |
JFormattedTextField.AbstractFormatterFactory
Delivers instances of an
JFormattedTextField.AbstractFormatter for
a specific value type for a JFormattedTextField. |
JTextField.AccessibleJTextFieldJTextComponent.AccessibleJTextComponent, JTextComponent.KeyBindingJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static int |
COMMIT
The possible focusLostBehavior options
|
static int |
COMMIT_OR_REVERT |
static int |
PERSIST |
static int |
REVERT |
notifyActionDEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYaccessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WESTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JFormattedTextField()
Creates a JFormattedTextField with no formatter factory.
|
JFormattedTextField(Format format)
Creates a JFormattedTextField that can handle the specified Format.
|
JFormattedTextField(JFormattedTextField.AbstractFormatter formatter)
Creates a JFormattedTextField with the specified formatter.
|
JFormattedTextField(JFormattedTextField.AbstractFormatterFactory factory)
Creates a JFormattedTextField with the specified formatter factory.
|
JFormattedTextField(JFormattedTextField.AbstractFormatterFactory factory,
Object value)
Creates a JFormattedTextField with the specified formatter factory and
initial value.
|
JFormattedTextField(Object value)
Creates a JFormattedTextField with the specified value.
|
| Modifier and Type | Method and Description |
|---|---|
void |
commitEdit()
Forces the current value from the editor to be set as the current
value.
|
Action[] |
getActions()
Gets the command list supplied by the UI augmented by the specific
Actions for JFormattedTextField.
|
int |
getFocusLostBehavior()
Returns the behaviour of this JFormattedTextField upon losing focus.
|
JFormattedTextField.AbstractFormatter |
getFormatter()
Returns the current formatter used for this JFormattedTextField.
|
JFormattedTextField.AbstractFormatterFactory |
getFormatterFactory()
Returns the factory currently used to generate formatters for this
JFormattedTextField.
|
String |
getUIClassID()
Returns the class ID for the UI.
|
Object |
getValue()
Returns the last valid value.
|
protected void |
invalidEdit()
This method is used to provide feedback to the user when an invalid value
is input during editing.
|
boolean |
isEditValid()
Returns true if the current value being edited is valid.
|
protected void |
processFocusEvent(FocusEvent evt)
Processes focus events.
|
void |
setDocument(Document newDocument)
Associates this JFormattedTextField with a Document and propagates
a PropertyChange event to each listener.
|
void |
setFocusLostBehavior(int behavior)
Sets the behaviour of this JFormattedTextField upon losing focus.
|
protected void |
setFormatter(JFormattedTextField.AbstractFormatter formatter)
Sets the formatter for this JFormattedTextField.
|
void |
setFormatterFactory(JFormattedTextField.AbstractFormatterFactory factory)
Sets the factory from which this JFormattedTextField should obtain
its formatters.
|
void |
setValue(Object newValue)
Sets the value that will be formatted and displayed.
|
addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, isValidateRoot, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setFont, setHorizontalAlignment, setScrollOffsetaddCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodListeners, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paramString, paste, read, removeCaretListener, removeInputMethodListener, removeKeymap, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, writeaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, 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, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, 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, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic static final int COMMIT
public static final int COMMIT_OR_REVERT
public static final int REVERT
public static final int PERSIST
public JFormattedTextField()
setValue or setFormatterFactory will
properly configure this text field to edit a particular type
of value.public JFormattedTextField(Format format)
format - the Format that this JFormattedTextField should be able
to handlepublic JFormattedTextField(JFormattedTextField.AbstractFormatter formatter)
DefaultFormatterFactory with this formatter as the default
formatter.formatter - the formatter to use for this JFormattedTextFieldpublic JFormattedTextField(JFormattedTextField.AbstractFormatterFactory factory)
factory - the formatter factory to use for this JFormattedTextFieldpublic JFormattedTextField(JFormattedTextField.AbstractFormatterFactory factory, Object value)
factory - the initial formatter factory for this JFormattedTextFieldvalue - the initial value for the text fieldpublic JFormattedTextField(Object value)
value - the initial value for this JFormattedTextFieldpublic void commitEdit() throws ParseException
ParseException - if the formatter cannot format the current valuepublic Action[] getActions()
getActions in class JTextFieldTextUI.getEditorKit(javax.swing.text.JTextComponent),
EditorKit.getActions()public int getFocusLostBehavior()
COMMIT, COMMIT_OR_REVERT,
PERSIST, or REVERT.public JFormattedTextField.AbstractFormatter getFormatter()
public JFormattedTextField.AbstractFormatterFactory getFormatterFactory()
public String getUIClassID()
JTextFieldgetUIClassID in class JTextFieldJComponent.setUI(javax.swing.plaf.ComponentUI),
JComponent.updateUI()public Object getValue()
protected void invalidEdit()
public boolean isEditValid()
protected void processFocusEvent(FocusEvent evt)
processFocusEvent in class Componentevt - the FocusEventFocusListener,
Component.addFocusListener(FocusListener),
Component.enableEvents(long)public void setDocument(Document newDocument)
setDocument in class JTextFieldnewDocument - the Document to associate with this text fieldpublic void setFocusLostBehavior(int behavior)
COMMIT, COMMIT_OR_REVERT,
PERSIST, or REVERT or an
IllegalArgumentException will be thrown.behavior - IllegalArgumentException - if behaviour is not
one of the aboveprotected void setFormatter(JFormattedTextField.AbstractFormatter formatter)
formatter - the AbstractFormatter to use for formatting the value for
this JFormattedTextFieldpublic void setFormatterFactory(JFormattedTextField.AbstractFormatterFactory factory)
factory - the AbstractFormatterFactory that will be used to generate
formatters for this JFormattedTextField