title: Blackberry - How to do text wrapping in ListField with Checkboxes?
body: <p>I m creating a ListField with Checkboxes from  <a href="http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/How_To_-_Create_a_ListField_with_check_boxes.html?nodeid=1165752&amp;vernum=0" rel="nofollow noreferrer">How To - Create a ListField with check boxes</a><br>
  But I m not getting how to wrap Text in a row in that ListField.<br>
  I referred the thread
  <a href="http://supportforums.blackberry.com/t5/Java-Development/Text-Wrapping-for-text-in-List-Field-items/td-p/232896" rel="nofollow noreferrer">Text Wrapping for text in List Field items</a></p>
  
  <p>Here its written as  </p>
  
  <blockquote>
    <p>If all you are displaying is text, then I would go with the approach suggested by rab.</p>
  </blockquote>
  
  <p>I m displaying Text only in ListField which I want to wrap if it doesnt fit within device screen.<br>
  But i m not getting "approach suggested by rab"  in which How to calculate?</p>
  
  <blockquote>
    <p>String [] linesToDraw = calculate the number of lines depending on the row width  </p>
  </blockquote>
  
  <p>I m stucked at this so any details on this issue ?</p>
  
  <hr>
  
  <p>With ur logic I got </p>
  
  <pre><code>* split text on words
  * create string array and while words array not empty do
        o create string lineStr
        o while getFont().getAdvance(lineStr+" "+words[i]) &lt; row width move words[i] to lineStr
  </code></pre>
  
  <p>I m doing it like</p>
  
  <pre><code>if(getFont().getAdvance(lineStr+" "+words[i]) &lt; Display.getWidth())
  {
      lineStr += words[i];
  }
  </code></pre>
  
  <p>&amp; I m storing lineStr in a Vector linesToDraw as the same lineStr I m using for storing text of next row.</p>
  
  <p>&amp; in the end for drawing I m doing </p>
  
  <pre><code>for (int i = 0; i &lt; linesToDraw.size(); i++)
  { 
            String textToDraw = (String)linesToDraw.elementAt(i);
            graphics.drawText(textToDraw, 0, y, 0, w);
            y += fontHeight;
  }
  </code></pre>
  
  <p>but how to calculate no. of lines of a row &amp; row height?</p>
  
  <p>so that with this row height I can write setRowHeight(rowHeight) as the row height is different for different rows.</p>
  
  <hr>
  
  <p>I got the no. of lines properly according to row width &amp; stored it in a Vector &amp; i m doing</p>
  
  <pre><code>int fontHeight = this.getFont().getHeight();
  
       for (int i = 0; i &lt; linesToDraw .size(); i++)
      {           
          textToDraw = (String)linesToDraw.elementAt(i);
          graphics.drawText(textToDraw, xpos, ypos, 0 , width);
          ypos += fontHeight;
      }
  </code></pre>
  
  <p>now its drawing the lines but over the previous one as by default listField.setRowHeight() is taking only one row. If there r 2 rows then I write setRowHeight(getFont().getHeight()*2) in drawListRow() but then it goes in loop</p>
  
  <p>If I write setRowHeight() while creating ListField then it comes properly but for all rows same row height is set.</p>
  
  <p>I gets the String to draw at Runtime &amp; the row height should be variable for different rows then how can I setRowHeight() with what parameter &amp; in which method ?</p>