Java GroupLayout异常 [英] Java GroupLayout Exception

查看:94
本文介绍了Java GroupLayout异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);
}
}

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

I'm trying to run it but i've got the following exception:

线程"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 =,horizo​​ntalAlignment = LEADING,horizo​​ntalTextPosition = TRAILING,iconTextGap = 4,labelFor =,text = a,verticalAlignment = CENTER,verticalTextPosition = CENTER]未附加到水平组

出什么问题了?我该如何解决?

What's the problem? How can I fix it?

推荐答案

您必须同时指定水平和垂直布局,另请参见

You have to specify both a horizontal and a vertical layout, also see GroupLayout giving error with java swing

我建议您使用一种工具来帮助您构建GUI.

I suggest you use a tool to help you build the GUI.

这篇关于Java GroupLayout异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆