|
|||||||||
| Home >> All >> com >> javathis >> utilities >> [ ui overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.javathis.utilities.ui
Class JTTextField

java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
com.javathis.utilities.ui.JTTextField
- All Implemented Interfaces:
- javax.accessibility.Accessible, javax.swing.event.CaretListener, java.util.EventListener, java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, javax.swing.Scrollable, java.io.Serializable, javax.swing.SwingConstants
- public class JTTextField
- extends javax.swing.JTextField
- implements javax.swing.event.CaretListener, java.awt.event.FocusListener, java.awt.event.MouseListener
- extends javax.swing.JTextField
JTTextField is an enhanced JTextField providing many features in a all-in-one Text Field.
Features:
- Can be one of four types of fields. String (Default), Double, Long, Currency.
- The length of the field can be set.
- Can be set to a Read Only mode.
- By default has a right click popup-menu for cut, copy, and paste. This can be disabled.
- Provides field formating for the number types.
| Nested Class Summary | |
(package private) static class |
JTTextField.InnerBorder
|
(package private) static class |
JTTextField.OuterBorder
|
| Nested classes inherited from class javax.swing.JTextField |
javax.swing.JTextField.AccessibleJTextField |
| Nested classes inherited from class javax.swing.text.JTextComponent |
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding |
| Nested classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| 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.Container |
|
| 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, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, 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 | |
JTTextField()
Constructs a new JTTextField. |
|
JTTextField(byte fieldType)
Constructs a new empty JTTextField with the specified field type. |
|
JTTextField(int columns)
Constructs a new empty JTTextField with the specified number of columns. |
|
JTTextField(int columns,
byte fieldType)
Constructs a new empty JTTextField with the specified number of columns, and field type. |
|
JTTextField(java.lang.String text)
Constructs a new JTTextField initialized with the specified text. |
|
JTTextField(java.lang.String text,
byte fieldType)
Constructs a new JTTextField initialized with the specified text, and field type. |
|
JTTextField(java.lang.String text,
int columns)
Constructs a new JTTextField initialized with the specified text and columns. |
|
JTTextField(java.lang.String text,
int columns,
byte fieldType)
Constructs a new JTTextField initialized with the specified text, columns, and field type. |
|
| Method Summary | |
private void |
buildRightClickMenu()
|
void |
caretUpdate(javax.swing.event.CaretEvent event)
Caret position has been updated |
void |
destroy()
Automaticly called if GC calls finalize method. |
protected void |
finalize()
Called by the garbage collector when it determines that there are no more references to this object. |
void |
focusGained(java.awt.event.FocusEvent e)
This method is called when a component gains the keyboard focus. |
void |
focusLost(java.awt.event.FocusEvent event)
This method is invoked when a component loses the keyboard focus. |
private static javax.swing.text.Document |
getDocument(byte fieldType)
|
byte |
getFieldType()
|
int |
getMaxLength()
|
int |
getMaxLengthFraction()
|
java.lang.String |
getUnformatedText()
Always returns the unformated contents of the field. |
java.lang.String |
getUnformatedText(int offset,
int length)
Always returns the unformated contents of the field. |
private void |
handleCurrencyFormating()
|
private void |
handleDoubleFormating()
|
private void |
handleLongFormating()
|
boolean |
isFocusable()
Returns true if the focus can be traversed. |
boolean |
isFormatingEnabled()
|
boolean |
isPopupMenuEnabled()
|
boolean |
isReadOnly()
|
private boolean |
isValidType(byte fieldType)
|
void |
jtInit()
Automaticly called at construction. |
void |
mouseClicked(java.awt.event.MouseEvent event)
This method is called when the mouse is clicked (pressed and released in short succession) on a component. |
void |
mouseEntered(java.awt.event.MouseEvent event)
This method is called when the mouse enters a component. |
void |
mouseExited(java.awt.event.MouseEvent event)
This method is called when the mouse exits a component. |
void |
mousePressed(java.awt.event.MouseEvent event)
This method is called when the mouse is pressed over a component. |
void |
mouseReleased(java.awt.event.MouseEvent event)
This method is called when the mouse is released over a component. |
void |
moveCaretPosition(int position)
Moves the caret to a new position, leaving behind a mark defined by the last time setCaretPosition was called. |
void |
setCaretPosition(int position)
Sets the position of the text insertion caret for the TextComponent. |
void |
setDocument(javax.swing.text.Document doc)
Method overrided to prevent the setting of a Document on a JTTextField. |
void |
setFieldType(byte fieldType)
Can be one of four types of fields. |
void |
setFormatingEnabled(boolean isFormatingEnabled)
Set to true to have the field formated with focus is lost, or false to disable formating. |
void |
setMaxLength(int maxLength)
Max Length less than one will revert to the default of the field type. |
void |
setMaxLengthFraction(int maxLengthFraction)
Max Length of Fraction less than one will revert to the default of the field type. |
void |
setPopupMenuEnabled(boolean isPopupMenuEnabled)
Set to true to have the default popup menu, or false to disable the menu. |
void |
setReadOnly(boolean isReadOnly)
Changes the field's default background to match the default System Control color, to have no borders, to be non-editable, and to be non-focusable. |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
MAIN_RESOURCE_BUNDLE
private static final java.util.ResourceBundle MAIN_RESOURCE_BUNDLE
STRING_TYPE
public static final byte STRING_TYPE
- See Also:
- Constant Field Values
LONG_TYPE
public static final byte LONG_TYPE
- See Also:
- Constant Field Values
CURRENCY_TYPE
public static final byte CURRENCY_TYPE
- See Also:
- Constant Field Values
DOUBLE_TYPE
public static final byte DOUBLE_TYPE
- See Also:
- Constant Field Values
CURRENCY_SYMBOL
private static final java.lang.String CURRENCY_SYMBOL
DECIMAL_SEPARATOR
private static final char DECIMAL_SEPARATOR
GROUPING_SEPARATOR
private static final char GROUPING_SEPARATOR
MINUS_SIGN
private static final char MINUS_SIGN
MAX_LENGTH_STRING
private static final int MAX_LENGTH_STRING
- See Also:
- Constant Field Values
MAX_LENGTH_DOUBLE
private static final int MAX_LENGTH_DOUBLE
- See Also:
- Constant Field Values
MAX_LENGTH_LONG
private static final int MAX_LENGTH_LONG
- See Also:
- Constant Field Values
MAX_LENGTH_FRACTION
private static final int MAX_LENGTH_FRACTION
- See Also:
- Constant Field Values
MAX_LENGTH_COMBO
private static final int MAX_LENGTH_COMBO
- See Also:
- Constant Field Values
DEFAULT_BACKGROUND
private final java.awt.Color DEFAULT_BACKGROUND
DEFAULT_BORDER
private final javax.swing.border.Border DEFAULT_BORDER
READ_ONLY_BACKGROUND
private final java.awt.Color READ_ONLY_BACKGROUND
READ_ONLY_BORDER
private final javax.swing.border.Border READ_ONLY_BORDER
currentType
private byte currentType
maxLength
private int maxLength
maxLengthFraction
private int maxLengthFraction
unformatedContents
private java.lang.String unformatedContents
isReadOnly
private boolean isReadOnly
isRequired
private boolean isRequired
isFocusable
private boolean isFocusable
isInit
private boolean isInit
isPopupMenuEnabled
private boolean isPopupMenuEnabled
isFormatingEnabled
private boolean isFormatingEnabled
orginalPopupMenuState
private boolean orginalPopupMenuState
rightClickMenu
private javax.swing.JPopupMenu rightClickMenu
cutMenuItem
private javax.swing.JMenuItem cutMenuItem
copyMenuItem
private javax.swing.JMenuItem copyMenuItem
pasteMenuItem
private javax.swing.JMenuItem pasteMenuItem
| Constructor Detail |
JTTextField
public JTTextField()
- Constructs a new JTTextField. The initial string is null, the number of
columns is set to 0, and the default field
type is String.
JTTextField
public JTTextField(byte fieldType)
- Constructs a new empty JTTextField with the specified field type.
The initial string is set to null, and the number of columns is 0. .
JTTextField
public JTTextField(int columns)
- Constructs a new empty JTTextField with the specified number of columns.
The initial string is set to null, and the default field type is String.
JTTextField
public JTTextField(int columns,
byte fieldType)
- Constructs a new empty JTTextField with the specified number of columns,
and field type. The initial string is set to null.
JTTextField
public JTTextField(java.lang.String text)
- Constructs a new JTTextField initialized with the specified text.
The number of columns is 0.
JTTextField
public JTTextField(java.lang.String text, byte fieldType)
- Constructs a new JTTextField initialized with the specified text, and
field type. The number of columns is 0.
JTTextField
public JTTextField(java.lang.String text, int columns)
- Constructs a new JTTextField initialized with the specified text
and columns.
JTTextField
public JTTextField(java.lang.String text, int columns, byte fieldType)
- Constructs a new JTTextField initialized with the specified text, columns,
and field type.
| Method Detail |
jtInit
public void jtInit()
- Automaticly called at construction.
Can be called manually if you need to re-Init this component after it has
been destroyed. However, once it has been GC'd there is no guarantee as to
what will happen.
destroy
public void destroy()
- Automaticly called if GC calls finalize method.
However, this is not guaranteed, and if this component causes a memory
leak, it may need to be called manually, when needed.
setCaretPosition
public void setCaretPosition(int position)
- Sets the position of the text insertion caret for the TextComponent.
Note that the caret tracks change, so this may move if the underlying
text of the component is changed. If the document is null, does
nothing.
moveCaretPosition
public void moveCaretPosition(int position)
- Moves the caret to a new position, leaving behind a
mark defined by the last time setCaretPosition was
called. This forms a selection.
setDocument
public void setDocument(javax.swing.text.Document doc)
- Method overrided to prevent the setting of a Document on a JTTextField.
Note: If a custom Document is required, a JTextField should be used.
setFieldType
public void setFieldType(byte fieldType)
- Can be one of four types of fields. String (Default), Double, Long,
Currency.
Note: If the field type is invalid then not change will occur.
getFieldType
public byte getFieldType()
setReadOnly
public void setReadOnly(boolean isReadOnly)
- Changes the field's default background to match the default
System Control color, to have no borders, to be non-editable, and to be
non-focusable.
isReadOnly
public boolean isReadOnly()
isFocusable
public boolean isFocusable()
- Returns true if the focus can be traversed.
getUnformatedText
public java.lang.String getUnformatedText()
- Always returns the unformated contents of the field.
This is only differnt than getText if formating is enabled.
getUnformatedText
public java.lang.String getUnformatedText(int offset, int length) throws javax.swing.text.BadLocationException
- Always returns the unformated contents of the field.
This is only differnt than getText if formating is enabled.
getMaxLength
public int getMaxLength()
setMaxLength
public void setMaxLength(int maxLength)
- Max Length less than one will revert to the default of the field
type. Defaults are always the max available to the field type.
Max total numbers allowed for double type left of decimal is 15. Max total numbers allowed for double type right of decimal is 15. With total numbers allowed on both sides not to exceed 17.
Max total numbers allowed for currency type left of decimal is 15. Max total numbers allowed for currency type right of decimal is 15. With total numbers allowed on both sides not to exceed 17. With formating on right of decimal will always be rounded to 2 places.
Max total numbers allowed for long type is 19.
Max total characters allowed for string type is 2,147,483,647.
However, the EXACT range of the numbers is not enforced, and if out of range with formating on will result in an unexpected number or zero.
Note: Paste attempts in which the resulting contents of the field would exceed its max length will be rejected.
getMaxLengthFraction
public int getMaxLengthFraction()
setMaxLengthFraction
public void setMaxLengthFraction(int maxLengthFraction)
- Max Length of Fraction less than one will revert to the default of the field
type. Defaults are always the max available to the field type.
Max total numbers allowed for double type left of decimal is 15. Max total numbers allowed for double type right of decimal is 15. With total numbers allowed on both sides not to exceed 17.
Max total numbers allowed for currency type left of decimal is 15. Max total numbers allowed for currency type right of decimal is 15. With total numbers allowed on both sides not to exceed 17. With formating on right of decimal will always be rounded to 2 places.
Long Types are not affect by this setting.
String Types are not affect by this setting.
However, the EXACT range of the numbers is not enforced, and if out of range with formating on will result in an unexpected number or zero.
setPopupMenuEnabled
public void setPopupMenuEnabled(boolean isPopupMenuEnabled)
- Set to true to have the default popup menu, or false to disable the menu.
Popup Menu is enabled by default.
isPopupMenuEnabled
public boolean isPopupMenuEnabled()
setFormatingEnabled
public void setFormatingEnabled(boolean isFormatingEnabled)
- Set to true to have the field formated with focus is lost, or false to
disable formating. If Formating is enabled it is only in effect when the
JTTextField does not have focus. When the field gains focus, it reverts
back to the unformated text.
Formating is disabled by default, and only effects number field types.
Note: If formating is enabled getText only returns the formated text if the JTTextField does not have focus. Unformated text can always be obtained by calling getUnformatedText().
isFormatingEnabled
public boolean isFormatingEnabled()
caretUpdate
public void caretUpdate(javax.swing.event.CaretEvent event)
- Description copied from interface:
javax.swing.event.CaretListener - Caret position has been updated
- Specified by:
caretUpdatein interfacejavax.swing.event.CaretListener
focusGained
public void focusGained(java.awt.event.FocusEvent e)
- Description copied from interface:
java.awt.event.FocusListener - This method is called when a component gains the keyboard focus.
- Specified by:
focusGainedin interfacejava.awt.event.FocusListener
focusLost
public void focusLost(java.awt.event.FocusEvent event)
- Description copied from interface:
java.awt.event.FocusListener - This method is invoked when a component loses the keyboard focus.
- Specified by:
focusLostin interfacejava.awt.event.FocusListener
mousePressed
public void mousePressed(java.awt.event.MouseEvent event)
- Description copied from interface:
java.awt.event.MouseListener - This method is called when the mouse is pressed over a component.
- Specified by:
mousePressedin interfacejava.awt.event.MouseListener
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent event)
- Description copied from interface:
java.awt.event.MouseListener - This method is called when the mouse is clicked (pressed and released
in short succession) on a component.
- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent event)
- Description copied from interface:
java.awt.event.MouseListener - This method is called when the mouse is released over a component.
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent event)
- Description copied from interface:
java.awt.event.MouseListener - This method is called when the mouse enters a component.
- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener
mouseExited
public void mouseExited(java.awt.event.MouseEvent event)
- Description copied from interface:
java.awt.event.MouseListener - This method is called when the mouse exits a component.
- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener
finalize
protected void finalize()
throws java.lang.Throwable
- Called by the garbage collector when it determines that there are no more
references to this object. Overrided to dispose of system resources and
to perform cleanup on this object.
handleLongFormating
private void handleLongFormating()
handleDoubleFormating
private void handleDoubleFormating()
handleCurrencyFormating
private void handleCurrencyFormating()
isValidType
private boolean isValidType(byte fieldType)
getDocument
private static javax.swing.text.Document getDocument(byte fieldType)
buildRightClickMenu
private void buildRightClickMenu()
|
|||||||||
| Home >> All >> com >> javathis >> utilities >> [ ui overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC