Class SwingValidationGroup
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)
-
Method Summary
Modifier and TypeMethodDescriptionfinal voidadd(AbstractButton[] buttons, Validator<Integer[]> validator) Add a validator of button models - typically to see if any are selected.final voidadd(AbstractButton[] buttons, Validator<Integer[]>... validators) Add a validator of button models - typically to see if any are selected.final voidAdd a combo box to be validated using the passed validator.final voidAdd a combo box to be validated using the passed validatorsfinal voidAdd a JList to be validated using the passed validator.final voidAdd a JList to be validated using the passed validatorsfinal voidadd(JTextComponent comp, Validator<String> validator) Add a text component to be validated using the passed validator.final voidadd(JTextComponent comp, Validator<String>... validators) Add a text component to be validated using the passed validators.static SwingValidationGroupcreate(GroupValidator additionalGroupValidation, SwingComponentDecorationFactory decorator, ValidationUI... ui) Creates aSwingValidationGroup.static SwingValidationGroupcreate(GroupValidator additionalGroupValidation, ValidationUI... ui) Creates aSwingValidationGroup.static SwingValidationGroupcreate(ValidationUI... ui) final JComponentCreate a label which will show the current problem if any, which can be added to a panel that uses validationprotected final <T> ValidationUIdecorationFor(T comp) static StringGet a string name for a component using the following strategy: Checkjc.getClientProperty(CLIENT_PROP_NAME)If that returned null, calljc.getName()static voidsetComponentName(JComponent comp, String localizedName) Methods inherited from class ValidationItem
performValidation, runWithValidationSuspended
-
Method Details
-
create
-
create
public static SwingValidationGroup create(GroupValidator additionalGroupValidation, ValidationUI... ui) Creates aSwingValidationGroup. Will use aSwingComponentDecorationFactoryreturned bySwingComponentDecorationFactory.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 customSwingComponentDecorationFactory, callcreate(org.netbeans.validation.api.ui.GroupValidator, org.netbeans.validation.api.ui.swing.SwingComponentDecorationFactory, org.netbeans.validation.api.ui.ValidationUI[])- Parameters:
ui- Zero or moreValidationUI:s. Will be used by theSwingValidationGroupto show the leading problem (if any)
-
create
public static SwingValidationGroup create(GroupValidator additionalGroupValidation, SwingComponentDecorationFactory decorator, ValidationUI... ui) Creates aSwingValidationGroup.- Parameters:
additionalGroupValidation- may be nulldecorator- 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).ui- Zero or moreValidationUI:s. Will all be used by theSwingValidationGroupto show the leading problem (if any)
-
decorationFor
- Overrides:
decorationForin classValidationGroup
-
add
Add a text component to be validated using the passed validators.When a problem occurs, the created ValidationListener will use a
ValidationUIcreated by thisValidationGroupto 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.- Parameters:
comp- A text component such as aJTextFieldvalidators- One or more Validators
-
add
Add a text component to be validated using the passed validator.When a problem occurs, the created ValidationListener will use a
ValidationUIcreated by thisValidationGroupto 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 ofValidatorUtils.merge(Validator,Validator).- Parameters:
comp- A text component such as aJTextFieldvalidator- a validator
-
add
Add a combo box to be validated using the passed validatorsWhen a problem occurs, the created
ValidationListenerwill use aValidationUIcreated by thisValidationGroupto 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.
- Parameters:
box- A combo box componentvalidators- One or more Validators
-
add
Add a combo box to be validated using the passed validator.When a problem occurs, the created
ValidationListenerwill use aValidationUIcreated by thisValidationGroupto 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 ofValidatorUtils.merge(Validator,Validator).- Parameters:
box- A combo box componentvalidator- a validator
-
add
Add a JList to be validated using the passed validatorsWhen a problem occurs, the created
ValidationListenerwill use aValidationUIcreated by thisValidationGroupto 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.
- Parameters:
list- A JList componentvalidators- One or more Validators
-
add
Add a JList to be validated using the passed validator.When a problem occurs, the created
ValidationListenerwill use aValidationUIcreated by thisValidationGroupto 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 ofValidatorUtils.merge(Validator,Validator).- Parameters:
list- A JList componentvalidator- a validator
-
add
Add a validator of button models - typically to see if any are selected.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.
- Parameters:
buttons- The buttonsvalidators- A number of Validators
-
add
Add a validator of button models - typically to see if any are selected.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 ofValidatorUtils.merge(Validator,Validator).- Parameters:
buttons- The buttonsvalidator- a validator
-
createProblemLabel
Create a label which will show the current problem if any, which can be added to a panel that uses validation- Returns:
- A JLabel
-
nameForComponent
Get a string name for a component using the following strategy:- Check
jc.getClientProperty(CLIENT_PROP_NAME) - If that returned null, call
jc.getName()
- Parameters:
jc- The component- Returns:
- its name, if any, or null
- Check
-
setComponentName
-