Class CollapsiblePanelField
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
-
Nested Class Summary
Nested Classes -
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
ConstructorsConstructorDescriptionCollapsiblePanelField(String labelText, boolean isInitiallyExpanded) Creates a new PanelField with an empty wrapped JPanel.CollapsiblePanelField(String labelText, boolean isInitiallyExpanded, LayoutManager layoutManager) Creates a new PanelField with an empty wrapped JPanel which has the given LayoutManager. -
Method Summary
Modifier and TypeMethodDescriptiongetPanel()Exposes the wrapped JPanel so that callers can add custom components to it.booleanWe need to override and return false unconditionally here, otherwise the rendering of this component within FormPanel will get wonky.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.booleanReports whether the panel is currently expanded or collapsed.static booleanReports whether a default border will be added to all new SliderField instances automatically.booleanBy default, FormFields occupy a single "line", or row, on the form.Sets the given border around the JSlider in this FormField.You can set the expand/collapse button on the left side (default) or on the right side of the form field.voidSets a default line border around the slider in this FormField.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.static voidsetIsDefaultBorderEnabled(boolean enable) By default, all new instances of this class will give themselves a default LineBorder.setIsExpanded(boolean expand) Expands or collapses the wrapped JPanel.setShouldExpandHorizontally(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, hashCode, hasHelpLabel, isEnabled, isValid, isVisible, preRender, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, validate
-
Constructor Details
-
CollapsiblePanelField
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
Expands or collapses the wrapped JPanel. -
isExpanded
public boolean isExpanded()Reports whether the panel is currently expanded or collapsed. -
setButtonPosition
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
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:
hasFieldLabelin classFormField
-
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:
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.
-
setShouldExpandHorizontally
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
-