Setting the button label text alignment in a Flex ButtonBar control

The following example shows how you can change the text alignment of button labels in a ButtonBar control in Flex by setting the buttonStyleName and textAlign styles.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/07/setting-the-button-label-text-alignment-in-a-flex-buttonbar-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        ButtonBar {
            buttonStyleName: myCustomButtonStyleName;
        }

        .myCustomButtonStyleName {
            cornerRadius: 0;
            fontWeight: normal;
            textAlign: right;
        }
    </mx:Style>

    <mx:Array id="arr">
        <mx:Object label="Button" />
        <mx:Object label="ButtonBar" />
        <mx:Object label="CheckBox" />
        <mx:Object label="ColorPicker" />
    </mx:Array>

    <mx:ButtonBar id="buttonBar"
            dataProvider="{arr}"
            themeColor="haloSilver"
            buttonHeight="32"
            width="100%">
    </mx:ButtonBar>

</mx:Application>

View source is enabled in the following example.