Setting the border thickness on a NumericStepper control in Flex

The following example shows how you can set the border thickness on a Flex NumericStepper control by setting the borderThickness style.

The borderThickness style is only supported when the borderStyle style is set to “solid”.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/27/setting-the-border-thickness-on-a-numericstepper-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="borderThickness:">
                <mx:HSlider id="slider"
                        minimum="0"
                        maximum="10"
                        value="1"
                        snapInterval="1"
                        tickInterval="1"
                        liveDragging="true" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:NumericStepper id="numericStepper"
            borderStyle="solid"
            borderThickness="{slider.value}" />

</mx:Application>

View source is enabled in the following example.

You can also set the borderThickness style in an external .CSS file or <mx:Style /> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/27/setting-the-border-thickness-on-a-numericstepper-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        NumericStepper {
            borderStyle: solid;
            borderThickness: 10;
        }
    </mx:Style>

    <mx:NumericStepper id="numericStepper" />

</mx:Application>

Or, you can set the borderThickness style using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/27/setting-the-border-thickness-on-a-numericstepper-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

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

            private function init():void {
                numericStepper.setStyle("borderStyle", "solid");
            }

            private function slider_change(evt:SliderEvent):void {
                numericStepper.setStyle("borderThickness", evt.value);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="borderThickness:">
                <mx:HSlider id="slider"
                        minimum="0"
                        maximum="10"
                        value="1"
                        snapInterval="1"
                        tickInterval="1"
                        liveDragging="true"
                        change="slider_change(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:NumericStepper id="numericStepper"
            initialize="init();" />

</mx:Application>

One thought on “Setting the border thickness on a NumericStepper control in Flex

Comments are closed.