Class PanelField
By default, PanelFields do not show the validation label when the form is validated. But if you add a FieldValidator to your PanelField, then the validation label will appear when the form is validated.
The purpose of a PanelField is to allow a very easy way to create a custom FormField without actually extending the FormField class yourself. You can simply instantiate a PanelField and then render whatever you need. You can of course also write a corresponding FieldValidator for your PanelField to validate whatever value it contains, but at that point it might be easier to just extend FormField and create a custom implementation.
- Since:
- 2020-09-27
- Author:
- scorbo2
-
Field Summary
Fields inherited from class ca.corbett.forms.fields.FormField
DEFAULT_FONT, defaultFont, extraAttributes, fieldComponent, fieldLabel, fieldValidators, helpLabel, ICON_SIZE, identifier, isEnabled, isVisible, margins, validationLabel, valueChangedListeners -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new PanelField with an empty wrapped JPanel.PanelField(LayoutManager layoutManager) -
Method Summary
Modifier and TypeMethodDescriptiongetPanel()Exposes the wrapped JPanel so that callers can add custom components to it.booleanOverridden here as we generally don't want to show a validation label on a panel field.booleanSee setEnabledStatusIsPropagated for a description of this option.booleanBy default, FormFields occupy a single "line", or row, on the form.setEnabled(boolean isEnabled) Overridden here so we can optionally propagate the new enabled status to all contained components, depending on isEnabledStatusPropagated.protected voidsetEnabledRecursive(Container container, boolean isEnabled) Recurses through the list of contained components, passing on the given isEnabled status to each of them (and their own contained children, if any of our contained components are containers themselves).setEnabledStatusIsPropagated(boolean isPropagated) Determines what happens when setEnabled is invoked.setShouldExpand(boolean expand) Optionally make this FormField expand to fill the entire width of the parent FormPanel.booleanBy default, FormPanel will allocate only the space that the field component requires.Methods inherited from class ca.corbett.forms.fields.FormField
addAllExtraAttributes, addFieldValidator, addValueChangedListener, clearExtraAttribute, clearExtraAttributes, clearValidationResults, equals, fireValueChangedEvent, getDefaultFont, getExtraAttribute, getFieldComponent, getFieldLabel, getHelpLabel, getHelpText, getIdentifier, getMargins, getValidationLabel, hasFieldLabel, hashCode, hasHelpLabel, isEnabled, isValid, isVisible, preRender, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, validate
-
Constructor Details
-
PanelField
public PanelField()Creates a new PanelField with an empty wrapped JPanel. Use getPanel() to retrieve the panel and add your custom components to it. -
PanelField
-
-
Method Details
-
hasValidationLabel
public boolean hasValidationLabel()Overridden here as we generally don't want to show a validation label on a panel field. Will return true only if one or more FieldValidators have been explicitly assigned.- Overrides:
hasValidationLabelin classFormField
-
getPanel
Exposes the wrapped JPanel so that callers can add custom components to it.- Returns:
- The wrapped JPanel, which is empty by default.
-
setShouldExpand
Optionally make this FormField expand to fill the entire width of the parent FormPanel. Defaults to false. -
setEnabledStatusIsPropagated
Determines what happens when setEnabled is invoked. By default, Swing containers do not propagate the new enabled status to the components that they contain. But this might be unexpected compared to the behaviour of other FormField implementations. So, set this to true if you want to the setEnabled method in this FormField to propagate downwards recursively to all contained components. The default value is false.If the "all or nothing" options don't suit your particular use case, (that is, if you want setEnabled to apply to some of the contained components here, but not all of them), then you should create a derived class, override the setEnabled method, and implement your custom logic.
-
isEnabledStatusPropagated
public boolean isEnabledStatusPropagated()See setEnabledStatusIsPropagated for a description of this option.- Returns:
- true if setEnabled should act on all contained components in this panel (default false).
-
setEnabled
Overridden here so we can optionally propagate the new enabled status to all contained components, depending on isEnabledStatusPropagated. See setEnabledStatusIsPropagated for a description of this option.- Overrides:
setEnabledin classFormField- Parameters:
isEnabled- whether to enable or disable the components.
-
setEnabledRecursive
Recurses through the list of contained components, passing on the given isEnabled status to each of them (and their own contained children, if any of our contained components are containers themselves). -
isMultiLine
public boolean isMultiLine()Description copied from class:FormFieldBy default, FormFields occupy a single "line", or row, on the form. However, some FormFields may have a field component that spans multiple lines, like a multi-line text box, or a list, or a custom panel. Descendant classes can override the default false value here. It controls the placement of the field label. For tall form fields, the field label will be anchored to the top-left of its area.- Overrides:
isMultiLinein classFormField
-
shouldExpand
public boolean shouldExpand()Description copied from class:FormFieldBy default, FormPanel will allocate only the space that the field component requires. Descendant classes can override the default false value here to indicate that their field component should be allowed to expand as much space as is available to it. For example: PanelField.- Overrides:
shouldExpandin classFormField
-