Package ca.corbett.forms.fields
Class ButtonField
java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.ButtonField
Represents a FormField that can contain one or more buttons with configurable actions.
Internally, the buttons are grouped into a JPanel, which is set as this FormField's fieldComponent.
The layout defaults to a FlowLayout. The alignment, hgap, and vgap of the layout can be
modified with setAlignment, setHgap, and setVgap methods. Technically, callers can also
directly access or even swap out the LayoutManager by talking to the fieldComponent directly,
but if you need a highly customized layout, you might be better off using PanelField
or CollapsiblePanelField. That way, you have maximum control of the layout of your components.
Validation: by default, ButtonFields do not show a validation label when the form is validated. But if you add a FieldValidator to your ButtonField, then the validation label will appear when the form is validated.
Field label: by default, ButtonFields do not show a field label. You can manually enable a label by calling buttonField.getFieldLabel().setText("My Label").
- Since:
- swing-extras 2.6
- Author:
- scorbo2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intFields 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 an empty ButtonField with no buttons and with a default layout.ButtonField(List<Action> actions) Creates a ButtonField with the specified actions, each action corresponding to a button. -
Method Summary
Modifier and TypeMethodDescriptionAdds a button with the specified Action to this ButtonField.intOne of FlowLayout's alignment options: LEFT, CENTER, RIGHT, LEADING, or TRAILING from the FlowLayout class.intReturns the count of buttons currently in this ButtonField.Gets the preferred size of the buttons in this ButtonField, or null if the buttons should choose their own preferred size.intgetHgap()Gets the horizontal gap between buttons.intgetVgap()Gets the vertical gap between button rows.booleanOverridden here as we generally don't want to show a validation label on a button field.removeButton(String actionName) Removes the button with the specified action name from this ButtonField, if such a button exists.setAlignment(int alignment) One of FlowLayout's alignment options: LEFT, CENTER, RIGHT, LEADING, or TRAILING from the FlowLayout class.setButtonPreferredSize(Dimension preferredSize) Sets the preferred size of the buttons in this ButtonField.setEnabled(boolean isEnabled) Overridden here so we can enable/disable our buttons as needed.setHgap(int hgap) Sets the horizontal gap between buttons, and between buttons and the edge of the containing panel.setShouldExpand(boolean expand) Optionally make this field expand to fill the entire width of the parent FormPanel.setVgap(int vgap) Sets the vertical gap between buttons, and between buttons and the edge of the containing panel.booleanReports whether this ButtonField should expand to fill available horizontal space.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, isMultiLine, isValid, isVisible, preRender, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, validate
-
Field Details
-
DEFAULT_ALIGNMENT
public static final int DEFAULT_ALIGNMENT- See Also:
-
DEFAULT_HGAP
public static final int DEFAULT_HGAP- See Also:
-
DEFAULT_VGAP
public static final int DEFAULT_VGAP- See Also:
-
-
Constructor Details
-
ButtonField
public ButtonField()Creates an empty ButtonField with no buttons and with a default layout. -
ButtonField
Creates a ButtonField with the specified actions, each action corresponding to a button. The label for each button is taken from the Action's name property.- Parameters:
actions- the list of actions for the buttons
-
-
Method Details
-
shouldExpand
public boolean shouldExpand()Reports whether this ButtonField should expand to fill available horizontal space.- Overrides:
shouldExpandin classFormField
-
setShouldExpand
Optionally make this field expand to fill the entire width of the parent FormPanel. Defaults to false. -
getButtonCount
public int getButtonCount()Returns the count of buttons currently in this ButtonField. -
getAlignment
public int getAlignment()One of FlowLayout's alignment options: LEFT, CENTER, RIGHT, LEADING, or TRAILING from the FlowLayout class. -
setAlignment
One of FlowLayout's alignment options: LEFT, CENTER, RIGHT, LEADING, or TRAILING from the FlowLayout class. -
getHgap
public int getHgap()Gets the horizontal gap between buttons. -
getVgap
public int getVgap()Gets the vertical gap between button rows. -
setHgap
Sets the horizontal gap between buttons, and between buttons and the edge of the containing panel. -
setVgap
Sets the vertical gap between buttons, and between buttons and the edge of the containing panel. -
getButtonPreferredSize
Gets the preferred size of the buttons in this ButtonField, or null if the buttons should choose their own preferred size. -
setButtonPreferredSize
Sets the preferred size of the buttons in this ButtonField. If set to null, the buttons will choose their own preferred size. -
addButton
Adds a button with the specified Action to this ButtonField. The action name should be unique! -
removeButton
Removes the button with the specified action name from this ButtonField, if such a button exists. -
setEnabled
Overridden here so we can enable/disable our buttons as needed.- Overrides:
setEnabledin classFormField- Parameters:
isEnabled- whether to enable or disable the components.
-
hasValidationLabel
public boolean hasValidationLabel()Overridden here as we generally don't want to show a validation label on a button field. Will return true only if one or more FieldValidators have been explicitly assigned.- Overrides:
hasValidationLabelin classFormField
-