Problem with GridLayoutManager (IntelliJ IDEA)

Hello,

I am writing a small program with a GUI using the GridLayoutManager of
IntelliJ. I am using the IDEA Java IDE and the built-in GUI Designer.

At runtime I want to add buttons to a panel, hence I use the following code:

     JButton b = new JButton();
     // set some button properties (text, action listener, ...)
     panel.add( b );

When I run the program and I reach the add() call, I get the following
exception:

     java.lang.NullPointerException
     at
com.intellij.uiDesigner.core.GridLayoutManager.addLayoutComponent(GridLayoutManager.java:134)
     at java.awt.Container.addImpl(Container.java:1074)
     at java.awt.Container.add(Container.java:365)
     at ...WelcomeForm.addModule(WelcomeForm.java:39)

Since this code runs properly if I use another layout manager for the
panel, IMHO it must be related to the GridLayoutManager

I guess I need to provide a constraint object, i.e. use

     panel.add( b, constraintObject );

Probably when leaving this constraintObject away it uses null
implicitly, but that causes the NullPointerException.

But how to construct this constraintObject?

EDIT:
     Now I use the following code:

          panel.add( b, new GridConstraints() );

     but I have to include the forms_rt.jar of IDEA.
     Moreover I want to distribute the project in future...

Thanks in advance,
Matthias

1 comment

Hello Matthias,

IDEA's forms_rt.jar is licensed under the Apache 2 license, so you can redistribute
it with your application.

I am writing a small program with a GUI using the GridLayoutManager of
IntelliJ. I am using the IDEA Java IDE and the built-in GUI Designer.

At runtime I want to add buttons to a panel, hence I use the following
code:

JButton b = new JButton();
// set some button properties (text, action listener, ...)
panel.add( b );
When I run the program and I reach the add() call, I get the following
exception:

java.lang.NullPointerException
at
com.intellij.uiDesigner.core.GridLayoutManager.addLayoutComponent(Grid
LayoutManager.java:134)
at java.awt.Container.addImpl(Container.java:1074)
at java.awt.Container.add(Container.java:365)
at ...WelcomeForm.addModule(WelcomeForm.java:39)
Since this code runs properly if I use another layout manager for the
panel, IMHO it must be related to the GridLayoutManager

I guess I need to provide a constraint object, i.e. use

panel.add( b, constraintObject );

Probably when leaving this constraintObject away it uses null
implicitly, but that causes the NullPointerException.

But how to construct this constraintObject?

EDIT:
Now I use the following code:
panel.add( b, new GridConstraints() );

but I have to include the forms_rt.jar of IDEA.
Moreover I want to distribute the project in future...
Thanks in advance,
Matthias

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.