|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.swinglib.field.FieldValidator
public class FieldValidator
Applies a regular expression to a text field to check its validity. Provides an optional listener that will change the field's background color if invalid.
Note: the validator records the component's document at time of construction.
If you change the document, you must call reset().
| Constructor Summary | |
|---|---|
FieldValidator(JTextComponent component,
String regex)
Constructs a "listen-only" instance; you must explicitly call isValid() to check the field's state. |
|
FieldValidator(JTextComponent component,
String regex,
Color highlight)
Constructs a an instance that will change the field's background color when its contents are invalid, and revert to its parent's color when the contents are valid. |
|
FieldValidator(JTextComponent component,
String regex,
Color highlight,
Color normal)
Constructs a an instance that will change the field's background color to either a "normal" or a "highlight" color depending on the field's contents. |
|
| Method Summary | |
|---|---|
boolean |
isValid()
Determines whether the document is currently valid (note: this may be called within an event handler, as long as the update has been applied to the document). |
void |
reset()
Call this method if you change the document on the component. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FieldValidator(JTextComponent component,
String regex)
isValid() to check the field's state.
component - The component to listen to; the new instance is
attached as a DocumentListener.regex - A regular expression defining the valid contents
of the field. This will be applied on any change
to the underlying document.
public FieldValidator(JTextComponent component,
String regex,
Color highlight)
Note: the first check is performed by this constructor.
component - The component to listen to; the new instance is
attached as a DocumentListener.regex - A regular expression defining the valid contents
of the field. This will be applied on any change
to the underlying document.highlight - When the field is invalid, it will be set to this
color.
public FieldValidator(JTextComponent component,
String regex,
Color highlight,
Color normal)
Note: the first check is performed by this constructor. There is
no need to make a separate setBackground() call
on the component itself.
component - The component to listen to; the new instance is
attached as a DocumentListener.regex - A regular expression defining the valid contents
of the field. This will be applied on any change
to the underlying document.highlight - When the field is invalid, it will be set to this
color.normal - When the field is valid, it will be set to this color.| Method Detail |
|---|
public boolean isValid()
public void reset()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||