Class MarginsField

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

public class MarginsField extends FormField
A FormField implementation for viewing or editing a Margins instance. Margins instances have five properties: left, top, right, bottom, and internalSpacing. This FormField provides a NumberSpinner for each one, and the resulting value of this field is a Margins instance containing the current values of all five properties.
Since:
swing-extras 2.8
Author:
scorbo2
  • Constructor Details

    • MarginsField

      public MarginsField(String label)
    • MarginsField

      public MarginsField(String label, Margins initialValue)
  • Method Details

    • getMarginsObject

      public Margins getMarginsObject()
      Don't confuse this with the getMargins() method from the parent class! "getMargins()" will return the actual margins for this FormField, which is not what you're looking for. This method will return a Margins instance created from the current values of the five spinners - the value of this field.
      Returns:
      A Margins instance containing the current values of all five spinners.
    • setMarginsObject

      public MarginsField setMarginsObject(Margins margins)
      Sets our field values according to the given Margins instance. If the given instance is null, a new Margins instance with default values will be used instead.
      Parameters:
      margins - The Margins instance to copy values from, or null to use a new Margins instance with default values.
      Returns:
      This MarginsField instance, for chaining.
    • isMultiLine

      public boolean isMultiLine()
      We override this to return true, as we will consume multiple rows in the FormPanel.
      Overrides:
      isMultiLine in class FormField
    • setEnabled

      public FormField setEnabled(boolean isEnabled)
      Overridden here so we can enable or disable all of our spinners and labels as needed when the FormField itself is enabled or disabled.
      Overrides:
      setEnabled in class FormField
      Parameters:
      isEnabled - whether to enable or disable the components.
    • setHeaderLabel

      public MarginsField setHeaderLabel(String label)
      Sets an optional header label to display above the five spinners. The three options for labeling this field are:
      • No label. Pass "" or null for the label parameter to the constructor, or call getFieldLabel().setText(""), and the field label will be hidden. Don't pass in a header label, or set the header label to null, and it also will be hidden.
      • A field label (usual FormField behavior). Pass some label text to the constructor, and a field label will be shown to the left of the field, like a normal FormField. Don't pass in a header label, or set the header label to null, and the result will be that only the field label is shown.
      • A header label. Pass "" or null for the label parameter to the constructor to hide the field label. Then, pass some label text to this method to set the header label, and the header label will be shown above the five spinners.

      A fourth option would be to set both the field label and the header label together, but that seems redundant. It is an option, though, if you really like labeling stuff.

      Parameters:
      label - The text to show in the header label, or null to hide the header label.
      Returns:
      This MarginsField instance, for chaining.
    • getHeaderLabel

      public String getHeaderLabel()
      Returns the optional header label text, or null if the header label is not currently shown.
      Returns:
      The text of the header label, or null if the header label is not currently shown.