|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.objectwave.viewUtility.TextFieldChangeListener
This class with call it's onChange() method whenever the given text field's value changes. This is useful for triggering other actions (populating other controls based on the change, for instance), or for executing validations.
This class is intended to be initialized a little differently than is normally done, as it is self-registering. Instead of passing an instance of this class to a JTextField's addXxxListener() method, create an instance of this listener and pass the JTextField in the constructor. The constructor will register whatever is necessary.
There is no need to maintain a local reference to an instance of this listener since the JTextField will refer to it, thereby preventing garbage collection (at least until the JTextField is collected).
Example:
// ... JTextField tf = new JTextField(); // ... new TextFieldChangeListener(tf) { public abtract void onChange(String oldText, String newText) { System.out.println("Changed from '" + oldText + "' to '" + newText + "'"); } }; // ...
Field Summary | |
protected boolean |
alreadyHandled
|
protected java.lang.String |
currentText
|
protected javax.swing.JTextField |
textField
|
Constructor Summary | |
TextFieldChangeListener(javax.swing.JTextField newTextField)
Construct an instance of this class with the given text field. |
Method Summary | |
void |
actionPerformed(java.awt.event.ActionEvent e)
When the control performs and action, and the event has not been handled, call the onChange method. |
void |
focusGained(java.awt.event.FocusEvent e)
When the control gains focus, 'remember' the current field text. |
void |
focusLost(java.awt.event.FocusEvent e)
When the control loses focus, and the event has not been handled, call the onChange method. |
javax.swing.JTextField |
getTextField()
|
protected boolean |
isAlreadyHandled()
|
abstract void |
onChange(java.lang.String oldText,
java.lang.String newText)
Abstract method which must be implemented to define what action should be taken when the field focus changes. |
protected void |
setTextField(javax.swing.JTextField newTextField)
Set the text field and register self as focus and action listener. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected javax.swing.JTextField textField
protected java.lang.String currentText
protected boolean alreadyHandled
Constructor Detail |
public TextFieldChangeListener(javax.swing.JTextField newTextField)
newTextField
- Method Detail |
protected void setTextField(javax.swing.JTextField newTextField)
newTextField
- The new TextField valuepublic javax.swing.JTextField getTextField()
protected boolean isAlreadyHandled()
public void focusGained(java.awt.event.FocusEvent e)
focusGained
in interface java.awt.event.FocusListener
e
- public void focusLost(java.awt.event.FocusEvent e)
focusLost
in interface java.awt.event.FocusListener
e
- public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
e
- public abstract void onChange(java.lang.String oldText, java.lang.String newText)
oldText
- newText
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |