PDA

View Full Version : How to adjust a split position from code?



a1ik
28 Jul 2009, 7:10 AM
Hello!

My task is to develop a code that manages application layouts, i.e. saving and restoring all layout details such as widgets sizes and positions. I have no problems querying all needed layout metrics from the components and saving them on the server when I do layout saving. My challenge is applying these metrics when I am restoring the layout.

The parent of all components is a LayoutContainer controlled by BorderLayout (P). Its west region (W) is setup to be collapsible with a splitter. The rest of the content resides in the center region of P (C). When I use controls I can collapse and expand W with a mouse and container nicely resizes C to accommodate the changes. Also when I call collapse() and expand() methods on W I get the expected results - C fills the available area of P or shrinks. However, when I try to resize W by calling its setWidth() method, P doesn't adjust C and I end up with gaps between W and C or overlaps.

I tried calling layout() method on P but it doesn't help - it just restores everything to its original state. I tired to calculate expected width of C after adjustment and and applying it by calling C.setWidth() at the same time when I call W.setWidth(). This also doesn't work.

Please advice how to control the splitbar from the code. Is there a tutorial or samples on the subject?

Another question - are there proven techniques of saving and restoring application layouts? Something like Photoshop does with saving Workspaces.

Thank you,

--Alexander

a1ik
28 Jul 2009, 7:59 AM
I've just found a solution. Instead of calling W.setWidth() BorderLayoutData of P has to be updated with the following call to P.layout()!

Example:


//add W to P with default width 200
BorderLayoutData ld = new BorderLayoutData(LayoutRegion.WEST, 200, 100, 800);
ld.setSplit(true);
P.add(W, ld);
...


//move the splitter from 200 to 400
ld.setSize(400);
P.layout();