Flex - get label height after setting text property - apache-flex

I'm looping through a recordset, and for each item I create at runtime a spark Label and set the text property from a field of the recordset. The labels must have a fixed width and some text goes multiline.
I want to arrange the label vertically so I need to know the height of the label so I can place the next label properly, but when I try to read this property, after the labels is added through the addElement method, it returns 0.
Do you know how to get the label height?

Use a VGroup or a List for this instead. It will automatically handle this kind of behaviour for you. Make sure to set variableRowHeight to true.
Cheers

Related

How can I dedicate space to a label inside my component?

I have a textfield component with a label for errormessages. Whenever a errormessage appears, it missplaces the field with the error.
Is there anyway to preallocate the space needed for the errormessages?
Put your text label inside div with fixed height or width. Your space will always be there, and you show your text based on your error.

How do I truncate a Flex StyleableTextField after two lines?

In my Flex 4.5 mobile app, I have an actionScript item renderer (that derives from Flex's LabelItemRenderer). I want to fit in exactly 2 lines of text, and then truncate the rest. The width and height of the label are fixed and known statically.
How can I do this? The StyleableTextField.truncateToFit() method only works for one line of text.
I've set wordWrap = true, so the text now flows into the second line - but I need to truncate the text if it doesn't fit in two lines.
I need it to show all the text if there is only one line. (in both cases the label should be vertically middle-aligned in my renderer)
I know how to override layoutContents to do sizing and positioning etc of the StyleableTextField. So I'm looking specifically for ideas to implement custom text truncation with the StyleableTextField).
Any ideas?
Unless you're using something specific to the StyleableTextField try the s:Label. It has a property maxDisplayedLines which you could set to 2 and it will handle the truncation.

Flex: Determining number of lines a spark text area can hold without overflowing

I want to implement paging in a spark text area. For that I want to find out the number of lines a spark textArea can hold before the scrollbars appear and just feed that much lines to the text area.
http://blog.flexexamples.com/2010/01/13/determining-the-number-of-lines-in-a-spark-richeditabletext-control-in-flex-4/
The number of lines a TextArea can hold before a vertical ScrollBar appear is determinated by the heightInLines property.
The code
var number_of_lines:int=textArea.heightInLines;
will return inside the variable number_of_lines the number of lines you are looking for, and textArea is the id of the TextArea object you are checking.
var numLines:int=t.heightInLines;
var numChars:int=t.widthInChars;
The documentation:
spark.components.TextArea.heightInLines():Number The default height of
the control, measured in lines. The control's formatting styles, such
as fontSize and lineHeight, are used to calculate the line height in
pixels.
You would, for example, set this property to 5 if you want the height
of the RichEditableText to be sufficient to display five lines of
text.
If this property is NaN (the default), then the component's default
height will be determined from the text to be displayed.
This property will be ignored if you specify an explicit height, a
percent height, or both top and bottom constraints.
RichEditableText's measure() method uses widthInChars and
heightInLines to determine the measuredWidth and measuredHeight. These
are similar to the cols and rows of an HTML TextArea.
Since both widthInChars and heightInLines default to NaN,
RichTextEditable "autosizes" by default: it starts out very small if
it has no text, grows in width as you type, and grows in height when
you press Enter to start a new line.

wordWrap="true" does not work in Flex Datagrid

in Flex Datagrid, I need to support line wrap function in one column.
In theory I need to set wordWrap="true" and variableRowHeight="true". It works well.
But the problem is that if in the cloumn I set itemRenderer="lc.monitoring.logviewer.components.CustomColumnRenderer" properties, then the line wrap funciton does not take effect. It seems that the line wrap function can not work with itemRenderer in the datagrid column.
Any one can help me about this.
Don't use Label - it is for displaying a single line of text.
The Label control displays a single line of noneditable text. Use the Text control to create blocks of multiline noneditable text.
mx.controls.Text supports multiline text and wordwrap
If the control is not as wide as the text, the text will wordwrap. The text is always aligned top-left in the control.
You should try to override measure and updateDisplaylist inside your itemrenderer.
Your item renderer does not know how to resize the height in order to allow showing info inside the dg

how to wordwrap in flex tree node

I have a Tree object in my Flex code. It's width is 100%, and it is contained by a Panel with width=200. I am using a custom itemrenderer that extends TreeItemRenderer.
I need the text in each node to word wrap if it's too big (as happens often). I have tried
label.wordWrap = true;
in my item renderer without any luck. Any other suggestions?
If 'label' is an instance of the Label component, you won't be able to get it to wrap, no matter what you do, as the Label component doesn't support wrapping. Or, rather, is meant to be used only for single-line text.
If you are using a Label component, try using a Text component, instead. It's meant to display multi-line text.
With the default TreeItemRenderer you just need to set two properties on your Tree to enable wordWrap:
tree.variableRowHeight = true;
tree.wordWrap = true;
Enjoy.
What is the height that is set on the label? Is there enough room for the text to go vertically?
try setting the label width to a constant width. If your not able to do this because it needs to be dynamic then you need to override the update functions and set the width of the label then. The problem is the label hasn't calculated the actual 100% width at the time of rendering so it doesnt know it has to warp or not.
Dont Use Label. Use ' mx:Text width=" 100%" ' ( Text with 100% width) and it will wrap on its own.

Resources