Aligning labels in a flex popupbutton control's pop up menu

Source: Internet
Author: User
Tags cdata
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.