It's pretty common to need to put a button or some other component into the title bar of a Panel or TitleWindow component (I'm going to refer to both of these components as Panel components since they are nearly the same). The Flex Panel components don't provide any support for this, but it can be done by subclassing, overriding the createChildren method, and adding code to insert components into the titleBar UIComponent. (This technique is explained here and many other places.)
But it seems silly to have to create a new subclass for each different button or other component that you need to add to a panel. And this basic technique doesn't allow you to make any modifications to the title bar on the fly. It recently occurred to me that it would be really handy if title bars were handled just like the ControlBar component--as a container tag that you can put inside your Panel and then everything inside of it will automatically be placed in the proper location at the top of the Panel.
So... I created the BetterTitleWindow component which does exactly that. Here's some mxml illustrating its usage:
It's pretty simple. Just put the TitleBar tag inside the BetterTitleWindow and add any components you need inside the TitleBar. TitleBar is nothing more than an HBox, so as you can see in the example, you can set all of the usual HBox padding and alignment styles for controlling its layout. The TitleBar instance is then accessible through the titleBarContainer property of BetterTitleWindow, so you can add more components or change styles or anything else at runtime. Here's a small sample app that demonstrates this capability:
You can also download the project from our svn repository.
1 Comment