IntelliJ gui creator: JPanel gives runtime null pointer exception upon adding any component
For anybody who is using IntelliJ's GUI creator and receiving the same error, I fixed the problem by manually setting the panel's layout manager in the code instead of choosing different layout managers within the GUI creator.
Example:
questionPane.setLayout(new BoxLayout(questionPane, BoxLayout.PAGE_AXIS));
I've filed the issue as a bug on the JetBrains website and received the following answer:
For fix NPE, please add a child component to a JPanel with GridLayoutManager with GridConstraints like this:
panel.add(new JLabel(), new GridConstraints(...))
or use other layout.
Using the GridConstraints solved the problem for me just as using another LayoutManager.
I shortened & edited the answer for readability
I got the same error as you did. I have a JPanel with Layout Manager set to GridLayoutManager Intellij. When I tried to add any component to this panel, I was getting the exception.
I then went into the GUI editor and changed to BorderLayout and everything worked fine. I am not sure why it isn't working for you.