PDA

View Full Version : Collapsible panels



A.Rothe
28 Nov 2011, 1:48 AM
Hi,

I try to create the following:

* a ContentPanel A, which has a Borderlayout
* the panel A has on the region SOUTH two panels B and C
* B and C should be collapsible and have a split bar in the middle
* it should be possible to collapse B and I have the full panel C on the south of A
* it should be possible to collapse C and I have the full panel B on the south of A
* both panels B and C should not be collapsed at the same time
* I can resize B (it changes the width of C) and vice versa

The first try with a LayoutContainer on the south of A, which has also a BorderLayout, was not successful (setCollapsible(true) on B and C, setSplit(true) on C).

How can I solve that? At the moment I try to create my own ToolButtons which replace the panels B or C with a CollapsePanel. Is that the right way?

Thanks
André :-?

A.Rothe
2 Dec 2011, 7:37 AM
Hi,

I have found a solution, maybe someone needs it:

Both panels B and C have its own ToolButton, which is not managed by the layout manager. Within the selection listener I change the region of the panel to use the collapse feature of BorderLayout. Per default the panel B is on CENTER (in SOUTH of A, which has also a BorderLayout), and Panel C is on EAST.

If the user clicks on B's ToolButton, I will move B into region WEST, Panel C into CENTER and then I call BorderLayout.collapse(LayoutRegion.WEST).

If the user clicks on C's ToolButton, I will move C into region EAST, Panel B into CENTER and then I call BorderLayout.collapse(LayoutRegion.EAST).

You should also store the current size of each panel within its LayoutData (use ComponentHelper.getLayoutData(panel)), to restore the panel with the previous size.

The resizing problem I have solved with a listener on Events.Resize (registered on the surrounding LayoutContainer). Actually the size of the EAST region can not be greater then the MaxSize, which is specified within the LayoutData. You cannot set maxsize or minsize as percent, so you have to define static values. But this values depend on the size of the surrounding LayoutContainer or Viewport. To give the user the possibility to resize panel B and C, the split bar should be moveable over the whole width of panel A. So it is necessary to change the MaxSize of the panel B and C dynamically. The value should always leave enough space for the second panel (i.e. 50px).

If your LayoutContainer will be smaller, it can also occur, that your current panel size will be greater than the newly calculated MaxSize. The result is, that you see only one of the panels B and C. So you have recalculate the current size in a way, that it is always smaller than or equals to MaxSize.

André