forms
  1. forms
  2. FORMS-70

Call to ButtonBarFactory.buildWizardBar() generates IndexOutOfBoundsException

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: HEAD
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:

      Java 1.6_29, Windows and Linux
      JGoodies Forms version 1.4.2

      Description

      This call worked in version 1.2 not broken in version 1.4.2

      I recently bumped my dependency from JGoodies Forms version 1.2.1 to 1.4.2.

      Previously I was able to call

      ButtonBarFactory.buildWizardBar(
      new JButton[] {},
      (JButton) created[1],
      (JButton) created[2],
      (JButton) created[3],
      new JButton[]

      {(JButton) created[4]});

      but the new API complained that the first argument cannot be a zero length array. After inspecting the API source code indeed it is preferred to used "null" for the first parameter. That's fine, although I like to avoid passing null. So I change it to

      ButtonBarFactory.buildWizardBar(
      null,
      (JButton) created[1],
      (JButton) created[2],
      (JButton) created[3],
      new JButton[] {(JButton) created[4]}

      );

      After that the API call produced the exception

      Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: The column index 4 must be less than or equal to 3.
      at com.jgoodies.forms.layout.CellConstraints.ensureValidGridBounds(CellConstraints.java:935)
      at com.jgoodies.forms.layout.FormLayout.setConstraints(FormLayout.java:811)
      at com.jgoodies.forms.layout.FormLayout.addLayoutComponent(FormLayout.java:1094)
      at java.awt.Container.addImpl(Container.java:1107)
      at java.awt.Container.add(Container.java:942)
      at com.jgoodies.forms.factories.ButtonBarFactory.buildWizardBar(ButtonBarFactory.java:620)
      ...

      If you look at the ButtonBarFactory.java:620 you will find the call to getColumn()

      // Optionally overlay the finish and next button.
      if (overlaidFinish != null)

      { builder.getPanel().add(overlaidFinish, CC.xy(builder.getColumn(), 1)); }

      Should have been getColumn()-1

      // Optionally overlay the finish and next button.
      if (overlaidFinish != null)

      { builder.getPanel().add(overlaidFinish, CC.xy(builder.getColumn()-1, 1)); }

      This adjustment resolved the problem for me. This method did change its implementation code significantly enough from version 1.2.1 and perhaps this defect was not encountered during testing since overlaidFinish would have to be not null.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            j_johnson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: