GroupLayout giving error with java swing

送分小仙女□ 提交于 2019-12-01 01:11:23

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/4693741/grouplayout-giving-error-with-java-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!