Class Margins

java.lang.Object
ca.corbett.forms.Margins

public class Margins extends Object
Can be used to specify margins and padding around and inside a FormField, or any other component that supports this Margins class.

The left, right, top, and bottom properties apply margins outside the target component. That is, the space between the component and the edge of its container. For example, in the case of a FormField:

  • left - the "indent" between the left edge of the FormPanel and the left edge of the FormField.
  • right - the space between the right edge of the FormField and the right edge of the FormPanel.
  • top - the space between the top edge of the FormField and either the previous FormField on the same FormPanel, or the top edge of the FormPanel if this is the first FormField.
  • bottom - the space between the bottom edge of the FormField and either the next FormField on the same FormPanel, or the bottom edge of the FormPanel if this is the last FormField.

The internalSpacing property applies extra space within the component. For example, in the case of a FormField, this is the extra space between the various subcomponents of the FormField. That is, the space between the field label and the field component, between the field component and the help label, and between the help label and the validation label.

Any component that supports this Margins class can apply the properties in a way that makes sense for that component. The examples above are specific to FormField, but this Margins class can be used for other components as well.

Since:
swing-extras 2.4
Author:
scorbo2
  • Field Details

  • Constructor Details

    • Margins

      public Margins()
      Creates a new Margins instance with all properties set to a hard-coded default of 4 pixels.
    • Margins

      public Margins(int all)
      Creates a new Margins instance with all properties set to the given pixel value.
    • Margins

      public Margins(int left, int top, int right, int bottom, int internalSpacing)
      Creates a new Margins instance with the given properties (all values in pixels).
    • Margins

      public Margins(Margins other)
      Creates a new Margins instance by copying values from the given other Margins instance. If the given instance is null, this is equivalent to new Margins().
  • Method Details

    • copy

      public Margins copy(Margins other)
      Copies all values from the given other Margins instance. If the given instance is null, this call does nothing.
    • setAll

      public Margins setAll(int value)
      Set all values to the given pixel value.
    • getLeft

      public int getLeft()
    • setLeft

      public Margins setLeft(int left)
    • getTop

      public int getTop()
    • setTop

      public Margins setTop(int top)
    • getRight

      public int getRight()
    • setRight

      public Margins setRight(int right)
    • getBottom

      public int getBottom()
    • setBottom

      public Margins setBottom(int bottom)
    • getInternalSpacing

      public int getInternalSpacing()
    • setInternalSpacing

      public Margins setInternalSpacing(int internalSpacing)
    • addListener

      public Margins addListener(Margins.Listener listener)
      You can listen for changes to this Margins instance by adding a Listener. Whenever any property of this Margins instance is changed, all registered listeners will be notified via their marginsChanged() method.
    • removeListener

      public Margins removeListener(Margins.Listener listener)
      You can stop listening to this Margins instance by removing a Listener that was previously added via addListener().
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object