Aligning headers in a DateChooser control in Flex

by Peter deHaan on June 5, 2008

in DateChooser

The following example shows how you can align the month name and year in a Flex DateChooser control by setting the textAlign and headerStyleName styles.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/05/aligning-headers-in-a-datechooser-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.ListEvent;

            private function comboBox_change(evt:ListEvent):void {
                var cssObj:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".dateChooserHeaderStyles");
                cssObj.setStyle("textAlign", comboBox.selectedItem);
            }
        ]]>
    </mx:Script>

    <mx:Style>
        .dateChooserHeaderStyles {
            fontWeight: bold;
            textAlign: left;
        }
    </mx:Style>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="textAlign:">
                <mx:ComboBox id="comboBox"
                        dataProvider="[left,center,right]"
                        change="comboBox_change(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:DateChooser id="dateChooser"
            headerStyleName="dateChooserHeaderStyles" />

</mx:Application>

View source is enabled in the following example.

For an example of aligning the days in a Flex DateChooser control, see “Changing the Flex DateChooser control’s text alignment”.

{ 5 comments… read them below or add one }

1 Joseph June 6, 2008 at 1:02 am

Where’s the DateChooser? Am I missing something?

Reply

2 julio June 6, 2008 at 7:09 am

the page links to the wrong sample swf…
it displays the swf from “Changing the label text alignment in a FormItem container in Flex” instead!

Reply

3 peterd June 6, 2008 at 8:03 am

Joseph / julio,

Yeah sorry, I noticed that late last night, but was too lazy to rebuild SWFs before bed.

I’ll get the SWF fixed as soon as I can.

Peter

UPDATE: New SWF posted.

Reply

4 Anthony June 6, 2008 at 11:28 am

The problem I am having is that I have a calendar component that’s 575 in width and I can set the align to center but it only centers the month, the year is still to the right.

Reply

5 Anthony June 7, 2008 at 5:03 pm

Peter,

One more question while i’m on the calendar component. Is there a way to have multiple colors for certain days or added ranges? Like if I add a certain event for a day or maybe a holiday.

Thanks by the way for the help.

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: