Lovely bit of code. I modified it a bit, here is a version I found more useful for my application. It is 1) entirely self contained - you pass it a created JPanel and a title String and it sets up everything and 2)not debugged at all (just so you are aware).
This works great; however, is there a trick to making the container panel or the mainframe size expand/collapse along with the expand/collapse panel? I've tried different ways, but still haven't gotten it to be perfect. Any suggestions would be greatly appreciated.
Here is my version. Expandable by clicking on the border.
compile the class
create JFrame with netbeans
drag the class to the frame
recommended: add a panel inside the CollapsiblePanel that would be the holder for your all other controls (though the class should work even if you put several components inside it without additional holder-panel)