GroupLayout giving error with java swing
Asked Answered
T

1

9

I am getting a long list of errors. Can anyone suggest to me where I am going wrong with GroupLayout.

layout.setHorizontalGroup(
    layout.createSequentialGroup()
        .addComponent(new JLabel("Enter Book Name"))
        .addComponent(new JTextField("TextField", 20))
);

Error:

    Exception in thread "main" java.lang.IllegalStateException:
        javax.swing.JTextField[,0,0,0x0,invalid,layout=javax.swing.
            plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,
            alignmentY=0.0,border=javax.swing.plaf.BorderUIResource$
            CompoundBorderUIResource@3d0bbf9e,flags=296,maximumSize=,
            minimumSize=,preferredSize=,caretColor=sun.swing.
            PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax
            .swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true
            ,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,
            bottom=0,right=0],selectedTextColor=sun.swing.
            PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.
            swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=20,
            columnWidth=0,command=,horizontalAlignment=LEADING]
            is not attached to a vertical group
            at javax.swing.GroupLayout.checkComponents(Unknown Source)
            at javax.swing.GroupLayout.prepare(Unknown Source)
Towery answered 14/1, 2011 at 17:3 Comment(3)
Myself, I avoid using this layout when hand-coding my GUI's. There are so many easier ones to use.Revers
I recommend a table based layout as the primary layout for any GUI. Search for "java table layout manager"; you can find mine at softwaremonkey.org/Code/MatrixLayoutBobbitt
Reformatted code; copyedited; please revert if incorrect.Pokelogan
G
17

When you use GroupLayout, you have to specify a Horizontal and a Vertical layout. Each component must be specified exactly once in each group. Not doing this causes this error.

Additionally, make sure you cross hatch each item properly. If you're making.a grid, be sure that both directions are sequences of parallels or vice versa. If you are making one row of buttons or something, make sure they are parallel one way and sequential another.

Giro answered 13/2, 2011 at 19:14 Comment(1)
Thanks, you really solve my problems... unlike of @SoftwareMonkey.Infant

© 2022 - 2024 — McMap. All rights reserved.