public final class SwingValidationGroup extends ValidationGroup
ValidationGroup subclass specialized for handling Swing
components. This subclass has add-methods for adding
GUI-components for common Swing cases. There are also a method for
getting the SwingComponentDecorationFactory used by this
SwingValidationGroup to create decorations for the separate
GUI-components added to the group. A custom SwingComponentDecorationFactory
can be specified when creating the SwingValidationGroup.
For components this library supports out-of-the-box such as
JTextFields or JComboBoxes, simply call
one of the add() methods with your component and
validators. For validating your own components or ones this class
doesn't have methods for, you implement ValidationListeners, and add them
to the ValidationGroup using the the method
ValidationGroup.addItem(org.netbeans.validation.api.ui.ValidationItem, boolean)
| Modifier and Type | Method and Description |
|---|---|
void |
add(javax.swing.AbstractButton[] buttons,
Validator<java.lang.Integer[]>... validators)
Add a validator of button models - typically to see if any are selected.
|
void |
add(javax.swing.AbstractButton[] buttons,
Validator<java.lang.Integer[]> validator)
Add a validator of button models - typically to see if any are selected.
|
void |
add(javax.swing.JComboBox box,
Validator<java.lang.String>... validators)
Add a combo box to be validated using the passed validators
|
void |
add(javax.swing.JComboBox box,
Validator<java.lang.String> validator)
Add a combo box to be validated using the passed validator.
|
void |
add(javax.swing.JList list,
Validator<java.lang.Integer[]>... validators)
Add a JList to be validated using the passed validators
|
void |
add(javax.swing.JList list,
Validator<java.lang.Integer[]> validator)
Add a JList to be validated using the passed validator.
|
void |
add(javax.swing.text.JTextComponent comp,
Validator<java.lang.String>... validators)
Add a text component to be validated using the passed validators.
|
void |
add(javax.swing.text.JTextComponent comp,
Validator<java.lang.String> validator)
Add a text component to be validated using the passed validator.
|
static SwingValidationGroup |
create(GroupValidator additionalGroupValidation,
SwingComponentDecorationFactory decorator,
ValidationUI... ui)
Creates a
SwingValidationGroup. |
static SwingValidationGroup |
create(GroupValidator additionalGroupValidation,
ValidationUI... ui)
Creates a
SwingValidationGroup. |
static SwingValidationGroup |
create(ValidationUI... ui) |
javax.swing.JComponent |
createProblemLabel()
Create a label which will show the current problem if any, which
can be added to a panel that uses validation
|
protected <T> ValidationUI |
decorationFor(T comp) |
static java.lang.String |
nameForComponent(javax.swing.JComponent jc)
Get a string name for a component using the following strategy:
Check
jc.getClientProperty(CLIENT_PROP_NAME)
If that returned null, call jc.getName()
|
static void |
setComponentName(javax.swing.JComponent comp,
java.lang.String localizedName) |
add, add, addItem, addUI, remove, removeUIperformValidation, runWithValidationSuspendedpublic static SwingValidationGroup create(ValidationUI... ui)
public static SwingValidationGroup create(GroupValidator additionalGroupValidation, ValidationUI... ui)
SwingValidationGroup.
Will use a SwingComponentDecorationFactory returned by SwingComponentDecorationFactory.getDefault() to modify the appearance of
subsequently added components (to show that there is a problem with a
component's content). To instead use a custom SwingComponentDecorationFactory, call
create(org.netbeans.validation.api.ui.GroupValidator, org.netbeans.validation.api.ui.swing.SwingComponentDecorationFactory, org.netbeans.validation.api.ui.ValidationUI[])ui - Zero or more ValidationUI:s. Will be used by the SwingValidationGroup to show the leading problem (if any)public static SwingValidationGroup create(GroupValidator additionalGroupValidation, SwingComponentDecorationFactory decorator, ValidationUI... ui)
SwingValidationGroup.additionalGroupValidation - may be nullui - Zero or more ValidationUI:s. Will all be used by the
SwingValidationGroup to show the leading problem (if any)decorator - A decorator to be used to modify the appearance of
subsequently added components (to show that there is a problem with a
component's content).protected final <T> ValidationUI decorationFor(T comp)
decorationFor in class ValidationGrouppublic final void add(javax.swing.text.JTextComponent comp,
Validator<java.lang.String>... validators)
When a problem occurs, the created ValidationListener will
use a ValidationUI created by this ValidationGroup to decorate
the component.
Note: All methods in this class must be called from the AWT Event Dispatch thread, or assertion errors will be thrown. Manipulating components on other threads is not safe.
Swing Documents (the model used by JTextComponent)
are thread-safe, and can be modified from other threads. In
the case that a text component validator receives an event on
another thread, validation will be scheduled for later,
on the event thread.
comp - A text component such as a JTextFieldvalidators - One or more Validatorspublic final void add(javax.swing.text.JTextComponent comp,
Validator<java.lang.String> validator)
When a problem occurs, the created ValidationListener will
use a ValidationUI created by this ValidationGroup to decorate
the component.
Note: All methods in this class must be called from the AWT Event Dispatch thread, or assertion errors will be thrown. Manipulating components on other threads is not safe.
Swing Documents (the model used by JTextComponent)
are thread-safe, and can be modified from other threads. In
the case that a text component validator receives an event on
another thread, validation will be scheduled for later,
on the event thread.
Unlike add(JTextComponent,Validator...), calling this method does not trigger warnings under -Xlint:unchecked.
If you wish to add more than one validator, simply add the result of ValidatorUtils.merge(Validator,Validator).
comp - A text component such as a JTextFieldvalidator - a validatorpublic final void add(javax.swing.JComboBox box,
Validator<java.lang.String>... validators)
When a problem occurs, the created ValidationListener will
use a ValidationUI created by this ValidationGroup to decorate
the component.
Note: All methods in this class must be called from the AWT Event Dispatch thread, or assertion errors will be thrown. Manipulating components on other threads is not safe.
box - A combo box componentvalidators - One or more Validatorspublic final void add(javax.swing.JComboBox box,
Validator<java.lang.String> validator)
When a problem occurs, the created ValidationListener will
use a ValidationUI created by this ValidationGroup to decorate
the component.
Note: All methods in this class must be called from the AWT Event Dispatch thread, or assertion errors will be thrown. Manipulating components on other threads is not safe.
Unlike add(JComboBox,Validator...), calling this method does not trigger warnings under -Xlint:unchecked.
If you wish to add more than one validator, simply add the result of ValidatorUtils.merge(Validator,Validator).
box - A combo box componentvalidator - a validatorpublic final void add(javax.swing.JList list,
Validator<java.lang.Integer[]>... validators)
When a problem occurs, the created ValidationListener will
use a ValidationUI created by this ValidationGroup to decorate
the component.
Note: All methods in this class must be called from the AWT Event Dispatch thread, or assertion errors will be thrown. Manipulating components on other threads is not safe.
list - A JList componentvalidators - One or more Validatorspublic final void add(javax.swing.JList list,
Validator<java.lang.Integer[]> validator)
When a problem occurs, the created ValidationListener will
use a ValidationUI created by this ValidationGroup to decorate
the component.
Note: All methods in this class must be called from the AWT Event Dispatch thread, or assertion errors will be thrown. Manipulating components on other threads is not safe.
Unlike add(JList,Validator...), calling this method does not trigger warnings under -Xlint:unchecked.
If you wish to add more than one validator, simply add the result of ValidatorUtils.merge(Validator,Validator).
list - A JList componentvalidator - a validatorpublic final void add(javax.swing.AbstractButton[] buttons,
Validator<java.lang.Integer[]>... validators)
Note: All methods in this class must be called from the AWT Event Dispatch thread, or assertion errors will be thrown. Manipulating components on other threads is not safe.
buttons - The buttonsvalidators - A number of Validatorspublic final void add(javax.swing.AbstractButton[] buttons,
Validator<java.lang.Integer[]> validator)
Note: All methods in this class must be called from the AWT Event Dispatch thread, or assertion errors will be thrown. Manipulating components on other threads is not safe.
Unlike add(AbstractButton[],Validator...), calling this method does not trigger warnings under -Xlint:unchecked.
If you wish to add more than one validator, simply add the result of ValidatorUtils.merge(Validator,Validator).
buttons - The buttonsvalidator - a validatorpublic final javax.swing.JComponent createProblemLabel()
public static java.lang.String nameForComponent(javax.swing.JComponent jc)
jc.getClientProperty(CLIENT_PROP_NAME)jc.getName()
jc - The componentpublic static void setComponentName(javax.swing.JComponent comp,
java.lang.String localizedName)