Class CollapsiblePanelField

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

public class CollapsiblePanelField extends FormField
Similar to PanelField, except this class gives you an "expand/contract" icon that allows the panel contents to be displayed or hidden. This allows you to provide additional controls or instructional labels on a FormPanel, with the ability to partially hide them when not needed.

Dev note: this component was written before the ActionPanel and its expandable/collapsible ActionGroups were implemented. In a way, this class ended up being a very rough prototype of ActionPanel. As such, it has only a small fraction of the number of configuration options that ActionPanel exposes. But, this FormField is still reasonably good at what it does, even if it isn't quite as sexy. So if you notice similarities in the basic design, it's not a coincidence.

Since:
swing-extras 2.5
Author:
scorbo2
  • Constructor Details

    • CollapsiblePanelField

      public CollapsiblePanelField(String labelText, boolean isInitiallyExpanded)
      Creates a new PanelField with an empty wrapped JPanel. Use getPanel() to retrieve the panel and add your custom components to it.
    • CollapsiblePanelField

      public CollapsiblePanelField(String labelText, boolean isInitiallyExpanded, LayoutManager layoutManager)
      Creates a new PanelField with an empty wrapped JPanel which has the given LayoutManager. Use getPanel() to retrieve the panel and add your custom components to it.
  • Method Details

    • setIsExpanded

      public CollapsiblePanelField setIsExpanded(boolean expand)
      Expands or collapses the wrapped JPanel.
    • isExpanded

      public boolean isExpanded()
      Reports whether the panel is currently expanded or collapsed.
    • setButtonPosition

      public CollapsiblePanelField setButtonPosition(CollapsiblePanelField.ButtonPosition position)
      You can set the expand/collapse button on the left side (default) or on the right side of the form field.
    • setDefaultBorder

      public void setDefaultBorder()
      Sets a default line border around the slider in this FormField. You can also invoke setBorder to set some custom border.
    • setBorder

      public CollapsiblePanelField setBorder(Border border)
      Sets the given border around the JSlider in this FormField. You can also invoke setDefaultBorder() to easily set a simple line border.
    • hasFieldLabel

      public boolean hasFieldLabel()
      We need to override and return false unconditionally here, otherwise the rendering of this component within FormPanel will get wonky. The CollapsiblePanelField maintains its own header with label and expand/collapse button, so we don't want FormPanel to add another label beside it. So, we pretend we have no field label even though we sort of do. Callers can still invoke getFieldLabel().getText() to retrieve our field label text, but this method will pretend that we have no field label so we can handle our own rendering of it.
      Overrides:
      hasFieldLabel in class FormField
    • isIsDefaultBorderEnabled

      public static boolean isIsDefaultBorderEnabled()
      Reports whether a default border will be added to all new SliderField instances automatically.
    • setIsDefaultBorderEnabled

      public static void setIsDefaultBorderEnabled(boolean enable)
      By default, all new instances of this class will give themselves a default LineBorder. You can disable that behavior with this method. Note that this only affects new instance creation from this point on - it will not change the border of any already-created instances.
    • 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.
    • setShouldExpandHorizontally

      public CollapsiblePanelField setShouldExpandHorizontally(boolean expand)
      Optionally make this FormField expand to fill the entire width of the parent FormPanel. Defaults to false.
    • setEnabledStatusIsPropagated

      public CollapsiblePanelField setEnabledStatusIsPropagated(boolean isPropagated)
      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

      public FormField setEnabled(boolean isEnabled)
      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:
      setEnabled in class FormField
      Parameters:
      isEnabled - whether to enable or disable the components.
    • setEnabledRecursive

      protected void setEnabledRecursive(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).
    • 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