Displaying item tool tips in a Flex ComboBox control
The following example shows how you can truncate long item labels in a ComboBox control by setting a custom item renderer. In this example we’re using the Label control we’re using the Label control and taking advantage of the Label control’s truncateToFit property which truncates the string with an “…” and displays a tool tip showing the entire, non-truncated string when the truncateToFit property is set to true (which is the default value).
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/26/displaying-item-tool-tips-in-a-flex-combobox-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
backgroundColor="white">
<mx:Array id="arr">
<mx:Object label="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." />
<mx:Object label="Donec sit amet dui nec pede aliquam auctor." />
<mx:Object label="Integer vestibulum sodales dui." />
<mx:Object label="Sed nonummy ligula et tortor." />
<mx:Object label="Aenean varius neque vel felis." />
<mx:Object label="Phasellus venenatis ipsum sit amet nisi." />
<mx:Object label="Nullam vitae turpis et ipsum cursus venenatis." />
<mx:Object label="Pellentesque tincidunt pede non arcu." />
<mx:Object label="Aliquam ut massa quis ante dignissim egestas." />
<mx:Object label="Curabitur facilisis velit sit amet metus." />
<mx:Object label="Vivamus ornare massa ac massa." />
<mx:Object label="Nam accumsan rutrum purus." />
</mx:Array>
<mx:ComboBox id="cb"
dataProvider="{arr}"
itemRenderer="mx.controls.Label"
width="200" />
</mx:Application>
View source is enabled in the following example.
I didn’t think this was interesting (or useful) enough to warrant a new entry, so I’ll just post it here. The following example shows how you can set a tool tip on both the ComboBox control as well as its dropdown menu. The ComboBox control on the left only sets the toolTip property, so the tool tip only displays while over the ComboBox itself, not when the mouse cursor is over the dropdown menu. The ComboBox control on the right sets the toolTip property in MXML and then uses the creationComplete event to call a method which sets the ComboBox control’s dropdown.toolTip property to the ComboBox control’s toolTip property.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/26/displaying-item-tool-tips-in-a-flex-combobox-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
verticalAlign="top"
backgroundColor="white">
<mx:Script>
<![CDATA[
private function init():void {
comboBox2.dropdown.toolTip = comboBox2.toolTip;
}
]]>
</mx:Script>
<mx:Array id="arr">
<mx:Object label="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." />
<mx:Object label="Donec sit amet dui nec pede aliquam auctor." />
<mx:Object label="Integer vestibulum sodales dui." />
<mx:Object label="Sed nonummy ligula et tortor." />
<mx:Object label="Aenean varius neque vel felis." />
<mx:Object label="Phasellus venenatis ipsum sit amet nisi." />
<mx:Object label="Nullam vitae turpis et ipsum cursus venenatis." />
<mx:Object label="Pellentesque tincidunt pede non arcu." />
<mx:Object label="Aliquam ut massa quis ante dignissim egestas." />
<mx:Object label="Curabitur facilisis velit sit amet metus." />
<mx:Object label="Vivamus ornare massa ac massa." />
<mx:Object label="Nam accumsan rutrum purus." />
</mx:Array>
<mx:ComboBox id="comboBox1"
dataProvider="{arr}"
toolTip="Please select some text."
width="200" />
<mx:ComboBox id="comboBox2"
dataProvider="{arr}"
toolTip="Please select some text."
width="200"
creationComplete="init();" />
</mx:Application>
View source is enabled in the following example.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
19 Responses to Displaying item tool tips in a Flex ComboBox control
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


I tried the first example on this page using “mx.controls.Text” for the “itemRenderer” property of ComboBox. I neither got a tooltip nor found the contents to be wrapped around. I am learning Flex. Your comments would be helpful to me.
Chandra Kumar,
Try something like the following instead:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"> <mx:Array id="arr"> <mx:Object label="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." /> <mx:Object label="Donec sit amet dui nec pede aliquam auctor." /> <mx:Object label="Integer vestibulum sodales dui." /> <mx:Object label="Sed nonummy ligula et tortor." /> <mx:Object label="Aenean varius neque vel felis." /> <mx:Object label="Phasellus venenatis ipsum sit amet nisi." /> <mx:Object label="Nullam vitae turpis et ipsum cursus venenatis." /> <mx:Object label="Pellentesque tincidunt pede non arcu." /> <mx:Object label="Aliquam ut massa quis ante dignissim egestas." /> <mx:Object label="Curabitur facilisis velit sit amet metus." /> <mx:Object label="Vivamus ornare massa ac massa." /> <mx:Object label="Nam accumsan rutrum purus." /> </mx:Array> <mx:ComboBox id="cb" dataProvider="{arr}" width="250" open="cb.dropdown.variableRowHeight = true;"> <mx:itemRenderer> <mx:Component> <mx:Text selectable="false" toolTip="{data.label}" /> </mx:Component> </mx:itemRenderer> </mx:ComboBox> </mx:Application>Peter
Peter,
Thank you. I followed the solution given by you. It works fine.
Chandra Kumar
Peter,
I wonder how mx.controls.TextInput control would be used as an item renderer for mx.controls.ComboBox control.
Chandra Kumar
Well, if some one want create ComboBox by Constructor. Please use:
var combo:ComboBox = new ComboBox();
combo.x = 3;
combo.y = 40;
combo.width = 138;
combo.itemRenderer = new ClassFactory(mx.controls.Label);
……..
best,
rosen
how to make arraylist items as tool tip for combobox items?
arraylist items[one ,two ,three, four, five]
combobox items[1,2,3,4,5]
eg:
if combobox item is 1 ,then the tool tip should be one
if combobox item is 2 ,then the tool tip should be two
@sabeerdeen,
I’d probably just listen for the
changeevent on the ComboBox control and dynamically set thetoolTipproperty based on the currently selected item.Peter
thank you so much , it is helpful for me!
How can I use the tooltip on the combo itself with the context of the selected option?
Whats the syntax? Any solution would be helpful.
@Shif,
This may depend largely on how your data provider is set up, but this should work for simpler cases:
For more complex data providers, you can probably do something similar to the following:
Peter
Thanx Peter, this worked:
toolTip=”{cBox.selectedItem.displayName}”
How can I truncate labels for each column in a combobox that shows 3 different columns formatted such that the second and third columns start from a given position.?
@av,
I really don’t think you could. You may want to look at using a PopUpButton and maybe a DataGrid and using truncation on each of the columns. Maybe something like “Using a DataGrid control as a pop up in the Flex PopUpButton control” and then hide the DataGrid column headers (“Toggling a Flex DataGrid control’s header row”). Then I think you can do the per-column truncation in the DataGrid by setting the item renderer to an MX Label control and setting the Boolean
truncateToFitproperty to true (“Truncating text in the Flex Label control using the truncateToFit property”).Or that’s my theory.
Peter
Actually, something like this should work:
Peter
Hi.. help me to find the solution for my problem
datagrid column should be embed with an image along with the datafield and if datafield length exceeds then tool tip should come if length not exceeded theree should not be tooltip..
So simple, yet works like a charm… Thanks! I was thinking of doing it the long way i.e. listening for change and calling a function to set the tool tip etc. You saved me a lot of time.
Hi,
I need to use tooltip long name of clients, but in my case i need to implement multiple checkbox also. So i am using different itemRenderer of my own. Now i want to ask you how can i implement this feature of tool tip in my code.
Hi,
I need to use tooltip long name of clients, but in my case i need to implement multiple checkbox also. So i am using different itemRenderer of my own. Now i want to ask you how can i implement this feature of tool tip in my code.
Saudações Sr. Peter
Seus códigos tem sido de extrema ajuda
Obrigado!