GroupLayout 在 java swing 中给出错误
我收到一长串错误。谁能向我建议 GroupLayout
。
layout.setHorizontalGroup(
layout.createSequentialGroup()
.addComponent(new JLabel("Enter Book Name"))
.addComponent(new JTextField("TextField", 20))
);
错误:
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 GroupLayout 时,必须指定水平和垂直布局。每个组件必须在每个组中精确指定一次。不这样做会导致此错误。
此外,请确保正确交叉孵化每个项目。如果您要制作网格,请确保两个方向都是平行线序列,反之亦然。如果您要制作一排按钮或其他东西,请确保它们以一种方式平行,另一种方式顺序。
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.