swingx and netbeans generated grouplayout code issues
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)