简体   繁体   English

GroupLayout给出了java swing的错误

[英]GroupLayout giving error with java swing

I am getting a long list of errors. 我得到了很多错误。 Can anyone suggest to me where I am going wrong with GroupLayout . 任何人都可以向我推荐我在GroupLayout出错的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)

When you use GroupLayout, you have to specify a Horizontal and a Vertical layout. 使用GroupLayout时,必须指定“水平”和“垂直”布局。 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. 如果你要制作一排按钮或其他东西,请确保它们是单向并行顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM