50% width with FormLayout

Contains useful source code for specific use cases.

50% width with FormLayout

Postby Development@SIB » Mon Jul 28, 2014 12:28 pm

If you have two components, e.g. GroupPanels and if you want that each group is 50% of the parent width, you could use following snippet:

Syntax: [ Download ] [ Hide ]
UIFormLayout layout = new UIFormLayout();
       
IConstraints center = layout.getHCenterConstraints(0, 5, -1, 5);

UILabel label = new UILabel();
label.setPreferredSize(5, 0);

panel.add(label, center);
panel.add(gpanLeft, layout.getConstraints(center.getTopAnchor(),
                                 layout.createAnchor(layout.getLeftMarginAnchor(), 0),
                                 center.getBottomAnchor(),
                                 layout.createAnchor(center.getLeftAnchor(), 0)));             
panel.add(gpanRight, layout.getConstraints(center.getTopAnchor(),
                                 layout.createAnchor(center.getRightAnchor(), 0),
                                 center.getBottomAnchor(),
                                 layout.createAnchor(layout.getRightMarginAnchor(), 0)));
User avatar
Development@SIB
 
Posts: 311
Joined: Mon Sep 28, 2009 1:54 pm

Return to Code snippets