Class GBC2

All Implemented Interfaces:
Serializable, Cloneable

public class GBC2 extends GridBagConstraints
A GridBagConstraints subclass for setting grid-like layouts where, usually, a left-side label is followed by one or more chooser components. Using this class means using a persistent instance of GridBagConstraints, so that e.g. insets or ipad values need to be set only once. Also, it makes use of call chaining (methods return this). Note that this class is written with the intention of leaving gridx and gridy entirely at the default (RELATIVE). Not doing that is likely to disrupt the methods; if specific values need to be used, it is likely better to use a basic GridBagConstraints instead of GBC2.
See Also:
  • Constructor Details

    • GBC2

      public GBC2()
    • GBC2

      public GBC2(Insets labelInsets, Insets otherInsets)
      Creates a new GBC2 which uses the given otherInsets for most of its components; the given labelInsets is only used when the forLabel() method is called.
      Parameters:
      labelInsets - Insets to use when adding a component with forLabel()
      otherInsets - Insets to use otherwise
  • Method Details

    • forLabel

      public GBC2 forLabel()
      Use this for a left-side label. It sets the anchor to east (right-alignment) and fill to NONE, so the JLabel does not need to use any specific alignment setting. This can also be used for empty labels to skip the label column. It can be directly used by calling panel.add(label, gbc.forLabel());
      Returns:
      This GridBagConstraints
    • oneColumn

      public GBC2 oneColumn()
      Use this for a single-column component other than the left-side label. It sets the anchor to west, fill to HORIZONTAL and the gridwidth to 1. It can be directly used by calling panel.add(component, gbc.oneColumn());
      Returns:
      This GridBagConstraints
    • eol

      public GBC2 eol()
      Use this for any component that ends a given row. It sets the anchor to west, fill to HORIZONTAL and the gridwidth to REMAINDER. It can be directly used by calling panel.add(component, gbc.eol());
      Returns:
      This GridBagConstraints
    • fullLine

      public GBC2 fullLine()
      Use this for any component that fills an entire row, like a section title. It sets the anchor to CENTER, fill to HORIZONTAL and the gridwidth to REMAINDER. It can be directly used by calling panel.add(component, gbc.fullLine());
      Returns:
      This GridBagConstraints
    • fullLineWithLabelInsets

      public GBC2 fullLineWithLabelInsets()
      Use this for any component that fills an entire row but still uses the label insets, like a panel with subcomponents. It sets the anchor to CENTER, fill to HORIZONTAL and the gridwidth to REMAINDER. It can be directly used by calling panel.add(component, gbc.fullLineWithLabelInsets());
      Returns:
      This GridBagConstraints
    • insets

      public GBC2 insets(int top, int left, int bottom, int right)
      change the insets of this GridBagConstraints
      Returns:
      this
      See Also:
    • clone

      public Object clone()
      Overrides:
      clone in class GridBagConstraints