Setting the header height on a Flex Panel container

by Peter deHaan on January 12, 2008

in Panel

The following example shows you how you can change the header height on a Panel container in Flex by setting the headerHeight style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/12/setting-the-header-height-on-a-flex-panel-container/ -->
<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="headerHeight:">
                <mx:HSlider id="slider"
                        minimum="24"
                        maximum="64"
                        value="32"
                        snapInterval="2"
                        tickInterval="4"
                        liveDragging="true" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:Panel id="panel"
            title="The quick brown fox jumped"
            status="{panel.width}x{panel.height}"
            titleIcon="@Embed('assets/Panel.png')"
            headerHeight="{slider.value}"
            borderColor="haloBlue"
            borderAlpha="1.0"
            width="400"
            height="150">
        <mx:VBox id="vBox" width="100%" height="100%">
            <mx:Label text="{vBox.width}x{vBox.height}" />
        </mx:VBox>
    </mx:Panel>

</mx:Application>

View source is enabled in the following example.

{ 9 comments… read them below or add one }

1 Alex Grande January 23, 2008 at 6:46 pm

Nice site. I’m happy to find it and am finding it useful.

The change in background color on this reply is nice too.

One thing I noticed is you are not separating your code. If you are going to teach people flex please teach them to use separate style sheets and follow best practices.

Thanks again! keep it up!

Alex

Reply

2 peterd January 23, 2008 at 7:42 pm

Alex,

No, I typically haven’t been separating code. I have on a few examples if I have a big data set (I may externalize the XML, for example).
Typically I leave it all in one code block so it is [hopefully] easier for people to copy/paste. Otherwise, they’ll have to right-click on the SWFs, select “View Source” and try and recreate the project piece by piece.

Peter

Reply

3 Antonio October 3, 2008 at 9:28 am

Hi, I’ve been working with flex for a couple of weeks now and i was looking for some way to put an image in the panel’s header just as you have on your example, i tried the same code

titleIcon="@Embed('assets/Panel.png')"

with of course the name of my file and the folder where it’s contained (this folder is contained in the main project folder). But it still doesn’t work, is there a specific location where the file must be or am I missing something??

Reply

4 peterd October 3, 2008 at 10:47 am

Antonio,

That code should work. If you are using Flex Builder 3, you should have the have the PNG file in the /src/assets/ folder, and your MXML file should be in the /src/ file.

You can download the project source code above and view the directory structure and probably try importing the project into Flex Builder.

Peter

Reply

5 Prashant Khanal November 22, 2008 at 11:47 pm

Hey Folks,

I see a dark line between header and body of my panel. I have set the border thickness to be zero from all sides. Is there any way to remove that?

Reply

6 Ganesh July 16, 2009 at 4:55 am

I have a list box inside the panel. I have an requirement to specify the height of the panel as the length of the data source which I gave for the list box.

Reply

7 Peter deHaan July 16, 2009 at 8:36 am

Ganesh,

I’d try creating a Panel and not specifying a height, that way the Panel container should size based on it’s children’s dimensions. Next, bind the nested List control’s rowCount property to the number of items in the List control’s data provider. That way, the List should always resize itself to the display all of its items (which may or may not look terrible, considering how many items you have in the List dataProvider).

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
 
    <mx:ApplicationControlBar dock="true">
        <mx:Button label="2 items" click="list.dataProvider = [1,2];" />
        <mx:Button label="4 items" click="list.dataProvider = [1,2,3,4];" />
        <mx:Button label="6 items" click="list.dataProvider = [1,2,3,4,5,6];" />
        <mx:Button label="10 items" click="list.dataProvider = [1,2,3,4,5,6,7,8,9,10];" />
        <mx:Button label="16 items" click="list.dataProvider = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];" />
    </mx:ApplicationControlBar>
 
    <mx:Panel title="Auto sizing Panel">
        <mx:List id="list" width="150" rowCount="{list.dataProvider.length}" />
    </mx:Panel>
 
</mx:Application>

Peter

Reply

8 Mark July 21, 2009 at 1:00 pm

Should headerHeight work in Gumbo? It does not for me.
The titlebar title is pushed down by a gray area’s height on a top is not changed.

Reply

9 Peter deHaan July 21, 2009 at 6:23 pm

Mark,

It should, but I believe there is currently an open bug on the issue: [SDK-21549] “Halo Panel headerHeight style does not function as expected with Spark Skin”.

Peter

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: