0 Replies Latest reply on May 1, 2007 12:50 PM by Newsgroup_User

    Constrain a label to a flexible length.

    Level 7
      I desire to constrain the text in a label to its width, but I want that
      width to be flexible when the browser is resized. When I use a
      percentage for the width of the label the text is not constrained,
      rather the label and any percentage width parent will expand to display
      the full text length. Am I missing something here.

      I have enclosed a small demonstration of this behavior. If you run this
      MXML, you will notice that in row2 the labels are constrained to a width
      of 150, but of course this width does not adjust if the browser is
      resized. In row1, the labels are set to be width of 25%, but the third
      label is not constrained, it is stretched to display the entire string
      and is no longer 1/4 of the width of the display.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      public var dataAry:Array = ["A short String","ABCDEF","A long string:
      The quick brown fox jumped over the lazy dog.","123456"];

      <mx:ArrayCollection id="data" source="{dataAry}"/>
      <mx:Panel layout="vertical" left="10" top="10" bottom="10" right="10"
      title="Relative Sizing">
      <mx:HBox width="100%">
      <mx:Repeater id="row1" dataProvider="{data}">
      <mx:Label text="{row1.currentItem}" width="25%" truncateToFit="true"/>
      <mx:HBox width="100%">
      <mx:Repeater id="row2" dataProvider="{data}">
      <mx:Label text="{row2.currentItem}" width="150" truncateToFit="true"/>