Oracle JEWT API Reference
Release 4.2.24.0.0
B12199-01

oracle.bali.ewt.text
Class NumberTextField

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.text.JTextComponent
                          |
                          +--javax.swing.JTextField
                                |
                                +--oracle.bali.ewt.text.NumberTextField
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable, javax.swing.SwingConstants

public class NumberTextField
extends javax.swing.JTextField

NumberTextField is a subclass of JTextField that only accepts numbers.

NumberTextField relies on the Document for filtering, so clients should never change the Document of the field.

End users will only be able to type in digits, the localized version of a plus and minus sign, and the localized version of the decimal separator.

The localized versions of the characters are based on the current locale of the NumberTextField.

Clients can set if the NumberTextField accepts the decimal separator with a call to setDecimal().

Clients can set if the NumberTextField allows the plus and minus characters by calling setSigned().

Clients can set the exact subclass of number to return by calling setDataType(). setDataType() takes a class object, like Integer.class and will automatically call setDecimal() depending on the Number class. Also all calls to getNumber() will return that specific Number subclass. Similarly, all calls to setNumber() will cast the Number object to the given data type.

The default DataType of the NumberTextField is Integer.

See Also:
Serialized Form

Inner Class Summary
 class NumberTextField.AccessibleNumberTextField
          The class used to obtain the accessible role for this object.
 
Inner classes inherited from class javax.swing.JTextField
javax.swing.JTextField.AccessibleJTextField
 
Inner classes inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Fields inherited from class javax.swing.JTextField
notifyAction
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
NumberTextField()
          Create the NumberTextField with a null number.
NumberTextField(int columns)
          Create the NumberTextField with the given number of columns.
NumberTextField(java.lang.Number number)
          Create the NumberTextField with the given Number object.
NumberTextField(java.lang.Number number, int columns)
          Create the NumberTextField with the given Number object and the given number of columns.
 
Method Summary
protected  java.lang.String convertNumberToString(java.lang.Number n)
          Called to convert the Number object into a String object.
protected  javax.swing.text.Document createDefaultModel()
          Creates the default implementation of the model to be used at construction if one isn't explicitly given.
 javax.accessibility.AccessibleContext getAccessibleContext()
          Get the AccessibleContext associated with this JComponent
 java.lang.Class getDataType()
          Get the DataType of the Number object.
 java.lang.Number getNumber()
          Get the Number object that is currently in the NumberTextField
 boolean isDecimal()
          Get if the NumberTextField allows the decimal separator.
 boolean isSigned()
          Does the NumberTextField allow + and - signs?
 void replaceSelection(java.lang.String content)
          Override to restore selection on invalid entries.
 void setDataType(java.lang.Class type)
          Set the data type of the Number object.
 void setDecimal(boolean isDecimal)
          Set if the NumberTextField allows the decimal separator.
 void setDecimal(boolean isDecimal, int maxDecimalDigits)
          Set if the NumberTextField allows the decimal separator.
 void setLocale(java.util.Locale locale)
           
 void setNumber(java.lang.Number n)
          Set the Number object that is currently in the NumberTextField.
 void setSigned(boolean signed)
          Set if the NumberTextField allows a + and - sign.
protected  boolean validateNumber(java.lang.Number n)
          Called to verify that the number is a valid entry.
 
Methods inherited from class javax.swing.JTextField
addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireActionPerformed, 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, 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, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberTextField

public NumberTextField()
Create the NumberTextField with a null number.

NumberTextField

public NumberTextField(java.lang.Number number)
Create the NumberTextField with the given Number object.

NumberTextField

public NumberTextField(int columns)
Create the NumberTextField with the given number of columns.

NumberTextField

public NumberTextField(java.lang.Number number,
                       int columns)
Create the NumberTextField with the given Number object and the given number of columns.
Method Detail

getNumber

public java.lang.Number getNumber()
Get the Number object that is currently in the NumberTextField

setNumber

public void setNumber(java.lang.Number n)
Set the Number object that is currently in the NumberTextField.


setDataType

public void setDataType(java.lang.Class type)
Set the data type of the Number object. This will automatically cast the existing number to the new Number subclass and automatically update the decimal property. All future getNumber() calls will return the Number datatype.
See Also:
getDataType()

getDataType

public java.lang.Class getDataType()
Get the DataType of the Number object. The default is Integer.
See Also:
setDataType(java.lang.Class)

isSigned

public boolean isSigned()
Does the NumberTextField allow + and - signs?

setSigned

public void setSigned(boolean signed)
Set if the NumberTextField allows a + and - sign. The default is true.

isDecimal

public boolean isDecimal()
Get if the NumberTextField allows the decimal separator.

setDecimal

public void setDecimal(boolean isDecimal)
Set if the NumberTextField allows the decimal separator.

setDecimal

public void setDecimal(boolean isDecimal,
                       int maxDecimalDigits)
Set if the NumberTextField allows the decimal separator. Use the indicated maximum number of decimal digits in the display.

Parameters:
isDecimal - should this field show decimals?
maxDecimalDigits - maximum number of digits to show, or -1 for default.

setLocale

public void setLocale(java.util.Locale locale)
Overrides:
setLocale in class java.awt.Component

replaceSelection

public void replaceSelection(java.lang.String content)
Override to restore selection on invalid entries.
Overrides:
replaceSelection in class javax.swing.text.JTextComponent

createDefaultModel

protected javax.swing.text.Document createDefaultModel()
Creates the default implementation of the model to be used at construction if one isn't explicitly given. An instance of PlainDocument is returned.
Overrides:
createDefaultModel in class javax.swing.JTextField
Returns:
the default model implementation

validateNumber

protected boolean validateNumber(java.lang.Number n)
Called to verify that the number is a valid entry. Subclassers can override this function to return false for invalid entries. By default, all numbers are accepted.
Parameters:
n - the number to be validated.
Returns:
true to accept the number, false to reject it

convertNumberToString

protected java.lang.String convertNumberToString(java.lang.Number n)
Called to convert the Number object into a String object. Clients can override this method to return a different String for their Number. This method is only called when setNumber() is called.

getAccessibleContext

public javax.accessibility.AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JComponent
Overrides:
getAccessibleContext in class javax.swing.JTextField
Returns:
the AccessibleContext of this JComponent

Oracle JEWT 4.2.24

Copyright © [xxxx],2003, Oracle. All Rights Reserved.