Swing GUI Builder Intellij IDEA
I cannot run the form in IntelliJ GUI builder
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
I am assuming that the code to initialize the views is automatically generated. Right now I only have it JPanel
, and somehow it is not auto-initialized, I even thought it was clearly visible on the designer.
This is a Gradle project and I decided to run the generated main function.
What do I need to do to make it work?
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);
}
}
+5
source to share
2 answers
see Intellij (Swing) GUI won't compile due to Gradle
solved by changing intellij settings (see also screenshot)
I checked:
- automatic import ...
- build and run using - set - intellij
- run tests using - set - intellij
- Gradle JVM - set - use JDK project
0
source to share