Adobe Flex Formitem label vertical alignment

Posted in Flex on August 10th, 2011 by cmanolescu – 1 Comment

If the child of a Formitem is a Combobox or Button, the label of the FormItem is vertically centered relative to the Button/Combobox height but if the child is anything else the label is vertically top aligned.

The reason for this is how the vertical position of the label is computed and if we take a look at updateDisplayList from FormItem we see that first child baselinePosition is used.

        if (numChildren > 0)
        {
            // Center label with first child
            child = getLayoutChildAt(0);
            childBaseline = child.baselinePosition;
            if (!isNaN(childBaseline))
                y += childBaseline - labelObj.baselinePosition;
        }

        labelObj.move(x, y);

In case of Button, ComboBox, TextInput, … baselinePosition is taken from the component that contains the text (eg. for DropDownList is labelDisplay:TextBase, for components that extend SkinnableTextBase is textDisplay:RichEditableText …) but for SkinnableComponent the FTETextUtil.calculateFontBaseline function is used.

Solutions:
1. In your custom component override public function get baselinePosition():Number or
2. Extend FormItem and override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void

One Comment on “ Adobe Flex Formitem label vertical alignment ”

  • Peter
    September 19th, 2012 3:09 pm

    Thanks buddy, I got it to work by overriding the baselinePosition in my custom component, just like you said !

Leave a Reply