Probably not too surprising to anybody, but you can easily control the location of an icon within a Button control by setting the button’s labelPlacement property.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.controls.ButtonLabelPlacement;

            [Bindable]
            [Embed('assets/flex_icon.gif')]
            private var Icon:Class;
        ]]>
    </mx:Script>

    <mx:Label text="Button.labelPlacement" />
    <mx:HBox>
        <mx:Button id="bLeft"
                width="120" height="100"
                icon="{Icon}"
                labelPlacement="{bLeft.label}"
                label="{ButtonLabelPlacement.LEFT}" />

        <mx:Button id="bRight"
                width="120" height="100"
                icon="{Icon}"
                labelPlacement="{bRight.label}"
                label="{ButtonLabelPlacement.RIGHT}" />

        <mx:Button id="bTop"
                width="120" height="100"
                icon="{Icon}"
                labelPlacement="{bTop.label}"
                label="{ButtonLabelPlacement.TOP}" />

        <mx:Button id="bBottom"
                width="120" height="100"
                icon="{Icon}"
                labelPlacement="{bBottom.label}"
                label="{ButtonLabelPlacement.BOTTOM}"/>
    </mx:HBox>

</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.

0 Responses to Positioning an icon within a button using the Button.labelPlacement property

  1. Arnaud says:

    Hello,

    For a more customizable button, have a look here:
    http://afoucal.free.fr/index.php/2008/12/03/flex-enhancedbutton-free-the-icon/

    The icon have its own x and y positions.

    Regards

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