The following example shows you how you can align the labels in a popupbutton control's pop up menu in Flex by setting
Popupstylename
And
Textalign
Styles <? XML version = "1.0" ?>
<! -- Http://blog.flexexamples.com/2008/01/18/aligning-labels-in-a-flex-popupbutton-controls-pop-up-menu/ -->
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml"
Layout = "Vertical"
Verticalalign = "TOP"
Backgroundcolor = "White" >
<MX: script>
<! [CDATA [
Import MX. Controls. Menu;
Import MX. Events. menuevent;
[Bindable]
Private var menu: menu;
Private function initmenu (): void {
Menu = new menu ();
Menu. dataprovider = arr;
}
]>
</MX: script>
< MX: Array ID = "Arr" >
< MX: Object Label = "Button" />
< MX: Object Label = "Buttonbar" />
< MX: Object Label = "Colorpicker" />
< MX: Object Label = "ComboBox" />
</ MX: Array >
<MX: Style>
. Mycustompopupstylename {
Textalign: left;
}
</MX: Style>
< MX: applicationcontrolbar Dock = "True" >
< MX: popupbutton ID = "Popupbutton"
Label = "Select a control... "
Popup = "{Menu }"
Popupstylename = "Mycustompopupstylename"
Preinitialize = "Initmenu ();" />
</ MX: applicationcontrolbar >
</MX: Application>
Or, if a dynamic example is a bit more your style...
<? XML version = "1.0" ?>
<! -- Http://blog.flexexamples.com/2008/01/18/aligning-labels-in-a-flex-popupbutton-controls-pop-up-menu/ -->
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml"
Layout = "Vertical"
Verticalalign = "TOP"
Backgroundcolor = "White" >
<MX: script>
<! [CDATA [
Import MX. Events. itemclickevent;
Import MX. Controls. Menu;
Import MX. Events. menuevent;
[Bindable]
Private var menu: menu;
Private function initmenu (): void {
Menu = new menu ();
Menu. dataprovider = arr;
}
Private function togglebuttonbar_itemclick (EVT: itemclickevent): void {
VaR OBJ: cssstyledeclaration = stylemanager. getstyledeclaration (". mycustompopupstylename ");
OBJ. setstyle ("textalign", EVT. Label );
Popupbutton. open ();
}
]>
</ MX: script >
< MX: Array ID = "Arr" >
< MX: Object Label = "Button" />
< MX: Object Label = "Buttonbar" />
< MX: Object Label = "Colorpicker" />
< MX: Object Label = "ComboBox" />
</ MX: Array >
<MX: Style>
. Mycustompopupstylename {
Textalign: left;
}
</MX: Style>
< MX: applicationcontrolbar Dock = "True" >
< MX: Form Stylename = "Plain" >
< MX: formitem Label = "Textalign :" >
< MX: togglebuttonbar ID = "Togglebuttonbar"
Selectedindex = "0"
Itemclick = "Togglebuttonbar_itemclick (event );" >
< MX: dataprovider >
< MX: Array >
< MX: Object Label = "Left" />
< MX: Object Label = "Center" />
< MX: Object Label = "Right" />
</ MX: Array >
</ MX: dataprovider >
</ MX: togglebuttonbar >
</ MX: formitem >
</ MX: Form >
</ MX: applicationcontrolbar >
< MX: popupbutton ID = "Popupbutton"
Label = "Select a control"
Popup = "{Menu }"
Popupstylename = "Mycustompopupstylename"
Preinitialize = "Initmenu ();" />
</MX: Application>