In a previous example, “Aligning items horizontally in a ControlBar container in Flex”, we saw how you could align items horizontally within a ControlBar container by setting the horizontalAlign style.
The following example shows how you can align controls vertically in a Flex ControlBar container by setting the verticalAlign style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/02/25/aligning-items-vertically-in-a-controlbar-container-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.events.ItemClickEvent;

            private function toggleButtonBar_itemClick(evt:ItemClickEvent):void {
                cBar.setStyle("verticalAlign", evt.label);
                panel.status = evt.label;
            }
        ]]>
    </mx:Script>

    <mx:Array id="arr">
        <mx:Object label="top" />
        <mx:Object label="middle" />
        <mx:Object label="bottom" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="verticalAlign:">
                <mx:ToggleButtonBar id="toggleButtonBar"
                        dataProvider="{arr}"
                        selectedIndex="1"
                        itemClick="toggleButtonBar_itemClick(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:Panel id="panel"
            width="320"
            height="240">
        <mx:Label text="Button" />
        <mx:Label text="ButtonBar" />
        <mx:Label text="CheckBox" />
        <mx:Label text="ColorPicker" />
        <mx:Label text="ComboBox" />
        <mx:Label text="DataGrid" />

        <mx:ControlBar id="cBar"
                height="100">
            <mx:Button label="Submit" />
            <mx:Button label="Cancel" />
        </mx:ControlBar>
    </mx:Panel>

</mx:Application>

View source is enabled in the following example.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree