Class PanelField

java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.PanelField

public class PanelField extends FormField
A FormField that wraps and exposes a JPanel, into which callers can render whatever extra custom components they want to display inline with the form. The wrapped JPanel will span the width of the form. Note that PanelFields have no field label, but you can certainly add one yourself inside the panel, along with whatever else you need.

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
  • 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

      public PanelField(LayoutManager layoutManager)
  • 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:
      hasValidationLabel in class FormField
    • getPanel

      public JPanel getPanel()
      Exposes the wrapped JPanel so that callers can add custom components to it.
      Returns:
      The wrapped JPanel, which is empty by default.
    • setShouldExpand

      public PanelField setShouldExpand(boolean expand)
      Optionally make this FormField expand to fill the entire width of the parent FormPanel. Defaults to false.
    • isMultiLine

      public boolean isMultiLine()
      Description copied from class: FormField
      By 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:
      isMultiLine in class FormField
    • shouldExpand

      public boolean shouldExpand()
      Description copied from class: FormField
      By 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:
      shouldExpand in class FormField