【发布时间】:2015-07-30 09:54:23
【问题描述】:
我似乎无法在 IntelliJ GUI builder 上运行表单
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
我假设初始化视图的代码是自动生成的。现在我只有一个 JPanel 并且不知何故它没有自动初始化,即使它在设计器上清晰可见。
这是一个 Gradle 项目,我选择使用生成的 main 函数运行。
我必须做些什么才能让它工作?
public class MyForm {
private JPanel jPanel;
public static void main(String[] args) {
JFrame frame = new JFrame("MyForm");
frame.setContentPane(new MyForm().jPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
【问题讨论】:
-
你是如何编译你的项目的?
-
@yole 这是一个 gradle 项目,我选择使用生成的 main 函数运行。
-
@AndrewThompson 我添加了更多细节
标签: java swing intellij-idea