If you have ever had the pleasure of working with both the Tab Navigator and the PopUpManager, you may have come across this lovely issue. Basically, when you have a Tab Navigator in a PopUp, the Label on the FIRST tab gets truncated when the PopUp is first launched. After you hover over the tab, the label is fixed. The best part is that when you hover over the tab, it doesn’t actually change its width – it’s quite frustrating.
Looking for solutions on the interwebz reveals a few gems, but none that I like – mainly because they involve hard-coding widths. After some minor digging around the Tab Navigator source and doing a few experiments, I found a solution of my own.
Its quite simple actually:
- The Tab Navigator is made up of several UIComponents in the standard Flex SDK. The actual tab that the user clicks is simply a Button.
- The Tab Navigator has a getTabAt() method, which returns a Button object.
- A Button, being a sub class of UIComponent, has the invalidateDisplayList() method. Calling this will
Mark a component so that its updateDisplayList() method gets called during a later screen update.
Put the above steps together and you can create a custom Tab Navigator that calls invalidateDisplayList() on it’s first Tab after the CREATION_COMPLETE event is fired. See below for the simple code…
package foo
{
import mx.containers.TabNavigator;
import mx.events.FlexEvent;
public class SweetTabNavigator extends TabNavigator
{
public function SweetTabNavigator()
{
super();
this.addEventListener(FlexEvent.CREATION_COMPLETE,
this.onCreationComplete);
}
protected function onCreationComplete(event:FlexEvent):void
{
this.getTabAt(0).invalidateDisplayList();
}
}
}
If you use this logic in your app, please extend Tab Navigator as seen above… Don’t go bloating your code with event handlers in the parent window, adding code inline in your MXML, etc…
Enjoy!