Skip to main content

swingx and netbeans generated grouplayout code issues

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2009-11-03

I want to share an issue i have, it's not a swingx issue but maybe someone will hit this so i think it's useful to write about it.

I am modifying some parts of an application in order to use swingx components.
The GUI has been designed using netbeaans gui editor and GroupLayout.

I am trying to convert a JPanel to a JXCollapsiblePanel.
Netbeans allows for custom creation code so what i do is this:
1) design the panel as a normal JPanel using GroupLayout and the GUI editor
2) modify the creation code so a JXCollapsiblePanel is generated.

This works but i hit this error at runtime:
"GroupLayout can only be used with one Container at a time"

I believe that the error is generated by the fact that Netbeans generates this code:

thePanel = new JXCollapsiblePane();
javax.swing.GroupLayout thePanelLayout = new javax.swing.GroupLayout(thePanel);

so basically it sets thePanel as the "host" for the GroupLayout then sets the layout on the panel itself.


JXCollapsiblePanel in its constructor sets up an internal JXPane as content pane and uses it when setLayout is called.

This causes the exception because now the host (the container specified during GroupLayput creation) is different from the actual container (the one used for setLayout)

The solution is to fix the GroupLayout creation but netbeans does not offer this feature (version 7.1 at least)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-06-08

You need to have the BeanInfo classes added to the designer to get this stuff to work correctly. There is a property that specifies the delegate for a container (as in JXCollapsiblePane's case). Without the BeanInfo any GUI designer will make the wrong assumptions.

And, no I have no idea how to set it. I don't like, nor do I use NetBeans.