I can't seem to run a form on IntelliJ GUI builder
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
I assume the code to initialize the views are auto generated. Right now I only have a JPanel
and somehow it is not auto-initialized even thought it's clearly visible on the designer.
It's a Gradle project and I've chosen to run with the generated main function.
What do I have to do to get it working?
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);
}
}
By default, the IntelliJ IDEA UI designer works by generating bytecode, which is unfortunately not supported with Gradle builds. You can change it to generate source code in Settings | Editor | GUI Designer.
see Intellij (Swing) GUI not compiling because of Gradle
solved by changing intellij settings (also see the screenshot)
i've checked:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.