Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swing GUI Builder Intellij IDEA

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);
    }
}
like image 728
user2798694 Avatar asked Jul 30 '15 09:07

user2798694


People also ask

Does IntelliJ IDEA use Swing?

IntelliJ IDEA is a pure Java Swing application. All the custom components like editor tabs are created manually, no third-party libraries are used for this. You can find all the details by looking at the IntelliJ IDEA Community Source code.


2 Answers

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.

like image 200
yole Avatar answered Oct 07 '22 18:10

yole


see Intellij (Swing) GUI not compiling because of Gradle

solved by changing intellij settings (also see the screenshot)

i've checked:

  • automaticaly import ...
  • build and run using - set - intellij
  • run tests using - set - intellij
  • Gradle JVM - set - Use project JDK
like image 44
Andrew Avatar answered Oct 07 '22 20:10

Andrew