Class Forms


  • public final class Forms
    extends java.lang.Object
    Provides convenience behavior for building frequently used categories of forms.
    Since:
    1.6
    Version:
    $Revision: 1.1 $
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Forms()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static javax.swing.JComponent border​(java.lang.String emptyBorderSpec, javax.swing.JComponent component)
      Deprecated.
      static javax.swing.JComponent border​(javax.swing.border.Border border, javax.swing.JComponent component)
      Creates and returns a panel where component is surrounded by the given border.
      private static javax.swing.JComponent buildGroupedButtonBar​(javax.swing.AbstractButton... buttons)
      Builds and returns a button bar that consists of the given buttons.
      private static javax.swing.JComponent buildGroupedButtonStack​(javax.swing.AbstractButton... buttons)
      Builds and returns a button bar that consists of the given buttons.
      static javax.swing.JComponent buttonBar​(javax.swing.JComponent... buttons)
      Creates and returns a panel where the given buttons are laid out horizontally using a ButtonBarBuilder.
      static javax.swing.JComponent buttonStack​(javax.swing.JComponent... buttons)
      Creates and returns a panel where the given buttons are laid out vertically using a ButtonStackBuilder.
      static javax.swing.JComponent centered​(javax.swing.JComponent component)
      Creates and returns a panel where component is centered.
      static javax.swing.JComponent checkBoxBar​(javax.swing.JCheckBox... checkBoxes)
      Builds and returns a panel where the given check boxes are laid out horizontally.
      static javax.swing.JComponent checkBoxStack​(javax.swing.JCheckBox... checkBoxes)
      Builds and returns a panel where the given check boxes are laid out vertically.
      static javax.swing.JComponent horizontal​(java.lang.String gapColSpec, javax.swing.JComponent... components)
      Builds and returns a panel where the given components are laid out horizontally separated by gaps as described by the given FormLayout gap (column) specification.
      static javax.swing.JComponent padding​(javax.swing.JComponent component, java.lang.String paddingSpec, java.lang.Object... args)
      Creates and returns a panel where component is surrounded by white space (an empty border) as described by paddingSpec.
      static javax.swing.JComponent padding​(javax.swing.JComponent component, javax.swing.border.EmptyBorder padding)
      Creates and returns a panel where component is surrounded by the given empty border.
      static javax.swing.JComponent radioButtonBar​(javax.swing.JRadioButton... radioButtons)
      Builds and returns a panel where the given radio buttons are laid horizontally.
      static javax.swing.JComponent radioButtonStack​(javax.swing.JRadioButton... radioButtons)
      Builds and returns a panel where the given radio buttons are laid vertically.
      static javax.swing.JComponent single​(java.lang.String columnSpec, java.lang.String rowSpec, javax.swing.JComponent component)
      Creates and returns a panel where component is laid out using a FormLayout with the given column and row specifications.
      static javax.swing.JComponent vertical​(java.lang.String gapRowSpec, javax.swing.JComponent... components)
      Builds and returns a panel where the given components are laid out vertically separated by gaps as described by the given FormLayout gap (row) specification.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Forms

        private Forms()
    • Method Detail

      • single

        public static javax.swing.JComponent single​(java.lang.String columnSpec,
                                                    java.lang.String rowSpec,
                                                    javax.swing.JComponent component)
        Creates and returns a panel where component is laid out using a FormLayout with the given column and row specifications.
         Forms.single(  "left:150dlu",      "c:p",     component);
         Forms.single(  "fill:150dlu:grow", "f:20dlu", component);
         Forms.single("center:150dlu",      "b:p:g",   component);
         
        Parameters:
        columnSpec - a FormLayout column specification for a single column
        rowSpec - a FormLayout row specification for a single row
        component - the component to lay out
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if columnSpec, rowSpec, or component is null
        java.lang.IllegalArgumentException - if columnSpec or rowSpec is empty or whitespace
      • centered

        public static javax.swing.JComponent centered​(javax.swing.JComponent component)
        Creates and returns a panel where component is centered. The panel grows both horizontally and vertically as its container grows.
         Forms.centered(anImageLabel);
         Forms.centered(anAnimatedPanel);
         
        Parameters:
        component - the component to center
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if component is null
      • border

        public static javax.swing.JComponent border​(javax.swing.border.Border border,
                                                    javax.swing.JComponent component)
        Creates and returns a panel where component is surrounded by the given border.
         Forms.border(new LineBorder(Color.GRAY), aComponent);
         
        Parameters:
        border - the border used to surround the component
        component - the component to wrap
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if border or component is null
      • border

        @Deprecated
        public static javax.swing.JComponent border​(java.lang.String emptyBorderSpec,
                                                    javax.swing.JComponent component)
        Deprecated.
        Creates and returns a panel where component is surrounded by an empty border as described by emptyBorderSpec.
         Forms.border("4dlu, 0, 4dlu, 8dlu", aComponent);
         Forms.border("10px 4px, 10px, 4px", aComponent);
         
        Parameters:
        component - the component to wrap
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if emptyBorderSpec or component is null
      • padding

        public static javax.swing.JComponent padding​(javax.swing.JComponent component,
                                                     javax.swing.border.EmptyBorder padding)
        Creates and returns a panel where component is surrounded by the given empty border.
         Forms.padding(aComponent, Paddings.DLU14);
         
        Parameters:
        component - the component to wrap
        padding - the empty border used to surround the component
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if border or component is null
      • padding

        public static javax.swing.JComponent padding​(javax.swing.JComponent component,
                                                     java.lang.String paddingSpec,
                                                     java.lang.Object... args)
        Creates and returns a panel where component is surrounded by white space (an empty border) as described by paddingSpec.
         Forms.padding(aComponent, "4dlu, 0, 4dlu,  8dlu");
         Forms.padding(aComponent, "10px 4px, 10px, %spx", left);
         
        Parameters:
        component - the component to wrap
        paddingSpec - describes the white space: top, left, bottom, right
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if paddingSpec or component is null
        See Also:
        padding(JComponent, EmptyBorder), Paddings.createPadding(String, Object...)
      • horizontal

        public static javax.swing.JComponent horizontal​(java.lang.String gapColSpec,
                                                        javax.swing.JComponent... components)
        Builds and returns a panel where the given components are laid out horizontally separated by gaps as described by the given FormLayout gap (column) specification.
         Forms.horizontal("4dlu",  component1, component2);
         Forms.horizontal("$rgap", component1, component2, component3);
         Forms.horizontal("0",     component1, component2, component3);
         
        Parameters:
        gapColSpec - describes the horizontal gap between the components
        components - the components to be laid out
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if components is null
        java.lang.IllegalArgumentException - if components is empty
      • vertical

        public static javax.swing.JComponent vertical​(java.lang.String gapRowSpec,
                                                      javax.swing.JComponent... components)
        Builds and returns a panel where the given components are laid out vertically separated by gaps as described by the given FormLayout gap (row) specification.
         Forms.vertical("4dlu",  component1, component2);
         Forms.vertical("$rgap", component1, component2, component3);
         Forms.vertical("0",     component1, component2, component3);
         
        Parameters:
        gapRowSpec - describes the vertical gap between the components
        components - the components to be laid out
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if components is null
        java.lang.IllegalArgumentException - if components is empty
      • buttonBar

        public static javax.swing.JComponent buttonBar​(javax.swing.JComponent... buttons)
        Creates and returns a panel where the given buttons are laid out horizontally using a ButtonBarBuilder. Equivalent to:
         ButtonBarBuilder.create().addButton(buttons).build();
         

        If class com.jgoodies.jsdl.common.focus.FocusTraversalUtils from the JSDL Common library is in the class path, it is used to build a focus group for the buttons. Focus is transferred between the buttons with cursor-left/-right.

        Parameters:
        buttons - the buttons to add to the button bar
        Returns:
        the built button bar
        Throws:
        java.lang.NullPointerException - if buttons is null
        java.lang.IllegalArgumentException - if buttons is empty
        See Also:
        ButtonBarBuilder
      • buttonStack

        public static javax.swing.JComponent buttonStack​(javax.swing.JComponent... buttons)
        Creates and returns a panel where the given buttons are laid out vertically using a ButtonStackBuilder. Equivalent to:
         ButtonStackBuilder.create().addButton(buttons).build();
         

        If class com.jgoodies.jsdl.common.focus.FocusTraversalUtils from the JSDL Common library is in the class path, it is used to build a focus group for the buttons. Focus is transferred between the buttons with cursor-left/-right.

        Parameters:
        buttons - the buttons to add to the button stack
        Returns:
        the built button stack
        Throws:
        java.lang.NullPointerException - if buttons is null
        java.lang.IllegalArgumentException - if buttons is empty
        Since:
        1.8
        See Also:
        ButtonStackBuilder
      • checkBoxBar

        public static javax.swing.JComponent checkBoxBar​(javax.swing.JCheckBox... checkBoxes)
        Builds and returns a panel where the given check boxes are laid out horizontally.

        If class com.jgoodies.jsdl.common.focus.FocusTraversalUtils from the JSDL Common library is in the class path, it is used to group the radio buttons. Focus is transferred to/from the selected button in a group; and cursor-left/-right change the selection in the group.

        Parameters:
        checkBoxes - the check boxes to lay out in a row
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if checkBoxes is null
        java.lang.IllegalArgumentException - if checkBoxes is empty
      • checkBoxStack

        public static javax.swing.JComponent checkBoxStack​(javax.swing.JCheckBox... checkBoxes)
        Builds and returns a panel where the given check boxes are laid out vertically.

        If class com.jgoodies.jsdl.common.focus.FocusTraversalUtils from the JSDL Common library is in the class path, it is used to group the radio buttons. Focus is transferred to/from the selected button in a group; and cursor-left/-right change the selection in the group.

        Parameters:
        checkBoxes - the check boxes to lay out in a stack
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if checkBoxes is null
        java.lang.IllegalArgumentException - if checkBoxes is empty
        Since:
        1.8
      • radioButtonBar

        public static javax.swing.JComponent radioButtonBar​(javax.swing.JRadioButton... radioButtons)
        Builds and returns a panel where the given radio buttons are laid horizontally.

        If class com.jgoodies.jsdl.common.focus.FocusTraversalUtils from the JSDL Common library is in the class path, it is used to group the radio buttons. Focus is transferred to/from the selected button in a group; and cursor-left/-right change the selection in the group.

        Parameters:
        radioButtons - the radio buttons to lay out in a row
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if radioButtons is null
        java.lang.IllegalArgumentException - if radioButtons is empty
      • radioButtonStack

        public static javax.swing.JComponent radioButtonStack​(javax.swing.JRadioButton... radioButtons)
        Builds and returns a panel where the given radio buttons are laid vertically.

        If class com.jgoodies.jsdl.common.focus.FocusTraversalUtils from the JSDL Common library is in the class path, it is used to group the radio buttons. Focus is transferred to/from the selected button in a group; and cursor-left/-right change the selection in the group.

        Parameters:
        radioButtons - the radio buttons to lay out in a stack
        Returns:
        the built panel
        Throws:
        java.lang.NullPointerException - if radioButtons is null
        java.lang.IllegalArgumentException - if radioButtons is empty
        Since:
        1.8
      • buildGroupedButtonBar

        private static javax.swing.JComponent buildGroupedButtonBar​(javax.swing.AbstractButton... buttons)
        Builds and returns a button bar that consists of the given buttons. Aims to build a focus group via the FocusTraversalUtils, if in the class path.
        Returns:
        the built panel
      • buildGroupedButtonStack

        private static javax.swing.JComponent buildGroupedButtonStack​(javax.swing.AbstractButton... buttons)
        Builds and returns a button bar that consists of the given buttons. Aims to build a focus group via the FocusTraversalUtils, if in the class path.
        Returns:
        the built panel