gpt4 book ai didi

Java GroupLayout 异常

转载 作者:行者123 更新时间:2023-12-01 23:50:36 35 4
gpt4 key购买 nike

public class Grouplayout implements Runnable {

public static void main(String[] args) {
SwingUtilities.invokeLater(new Grouplayout());
}

@Override
public void run() {
JFrame jFrame = new JFrame();
GroupLayout layout = new GroupLayout(jFrame.getContentPane());
jFrame.getContentPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);

JLabel jLabel1 = new JLabel("a");
JLabel jLabel2 = new JLabel("b");
JLabel jLabel3 = new JLabel("c");
JLabel jLabel4 = new JLabel("d");

layout.setVerticalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel4)));

jFrame.pack();
jFrame.setVisible(true);
}
}

我正在尝试运行它,但出现以下异常:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=a,verticalAlignment=CENTER,verticalTextPosition=CENTER] is not attached to a horizontal group

有什么问题吗?我该如何修复它?

最佳答案

您必须指定水平和垂直布局,另请参阅 GroupLayout giving error with java swing

我建议您使用一个工具来帮助您构建 GUI。

关于Java GroupLayout 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16347394/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com