A layout manager that allows multiple widgets of a {@link LayoutPanel} to belaid out either vertically or horizontally. The height and width of each widget in a {@code BoxLayout} can be specified by setting a{@link BoxLayoutData} object into the widget using{@link LayoutPanel#add(Widget,LayoutData)} and also by using CSS or acombination of both methods.
{@code BoxLayout} aligns all widgets in one row if the {@link Orientation}field is set to {@code HORIZONTAL}, and one column if it is set to {@code VERTICAL}.
NOTE: {@code BoxLayout} does not have the ability to wrap.
When a {@code BoxLayout} lays out widgets, it tries to size each widget atthe widget's preferred size. In the following example a {@link LayoutPanel}is set to use a {@code BoxLayout}. The default orientation of a {@code BoxLayout} is {@code HORIZONTAL}. The {@link LayoutPanel} is added decoratedto a {@link org.gwt.mosaic.ui.client.Viewport} so that it fills all browser'scontent area:
| public void onModuleLoad() { Viewport viewport = new Viewport(); LayoutPanel panel = new LayoutPanel(new BoxLayout()); panel.setPadding(10); panel.setWidgetSpacing(5); panel.add(new Button("Button 1")); panel.add(new Button("Button 2")); panel.add(new Button("Button 3")); panel.add(new Button("Button 4")); viewport.add(panel, true); RootPanel.get().add(viewport); } |
The next example sets the orientation of the {@link BoxLayout} to{@link Orientation#VERTICAL}:
| public void onModuleLoad() { Viewport viewport = new Viewport(); LayoutPanel panel = new LayoutPanel(new BoxLayout(Orientation.VERTICAL)); panel.setPadding(10); panel.setWidgetSpacing(5); panel.add(new Button("Button 1")); panel.add(new Button("Button 2")); panel.add(new Button("Button 3")); panel.add(new Button("Button 4")); viewport.add(panel, true); RootPanel.get().add(viewport); } |
{@code BoxLayoutData} can specify the size of the widgets. In the next twoexamples: Button 1 will be stretch to fill the available space in both directions (horizontally and vertical); Button 2 will be stretched only vertical, Button 3 will be stretched only horizontally; Button 4 and Button 5 will be set to a specific size by giving explicitly the width and height in pixels or ratios (values > 0 and <= 1 are ratios of the {@link LayoutPanel}'s client area except paddings, 0 and values> 1 are pixels, and -1 means preferred size).
| public void onModuleLoad() { Viewport viewport = new Viewport(); LayoutPanel panel = new LayoutPanel(new BoxLayout()); panel.setPadding(10); panel.setWidgetSpacing(5); panel.add(new Button("Button 1"), new BoxLayoutData(FillStyle.BOTH)); panel.add(new Button("Button 2"), new BoxLayoutData(FillStyle.VERTICAL)); panel.add(new Button("Button 3"), new BoxLayoutData(FillStyle.HORIZONTAL)); panel.add(new Button("Button 4"), new BoxLayoutData(-1.0, 0.5)); panel.add(new Button("Button 5"), new BoxLayoutData(-1.0, 150.0)); viewport.add(panel, true); RootPanel.get().add(viewport); } |
| public void onModuleLoad() { Viewport viewport = new Viewport(); LayoutPanel panel = new LayoutPanel(new BoxLayout(Orientation.VERTICAL)); panel.setPadding(10); panel.setWidgetSpacing(5); panel.add(new Button("Button 1"), new BoxLayoutData(FillStyle.BOTH)); panel.add(new Button("Button 2"), new BoxLayoutData(FillStyle.VERTICAL)); panel.add(new Button("Button 3"), new BoxLayoutData(FillStyle.HORIZONTAL)); panel.add(new Button("Button 4"), new BoxLayoutData(0.5, -1.0)); panel.add(new Button("Button 5"), new BoxLayoutData(150.0, -1.0)); viewport.add(panel, true); RootPanel.get().add(viewport); } |
@author georgopoulos.georgios(at)gmail.com
@see BoxLayoutData