views:

1428

answers:

2

I need to have a staticText to float below another element with variable height. I'm taking a sample from the book JasperReports for Java Programmers. It says that it's possible to do it. The difference with my sample is that I use a hard coded string in textFieldExpression, they use a $F{} field.

     <textField isStretchWithOverflow="true" hyperlinkType="None">
   <reportElement x="0" y="0" width="100" height="24"/>
   <box>
    <pen lineWidth="0.5" lineStyle="Solid"/>
   </box>
   <textElement/>
   <textFieldExpression class="java.lang.String"><![CDATA["jjjjjjjjjjj oooooooooo uuuuuuuuuu aaaaaaaaaa xxxxxxxxx u ttttt"]]></textFieldExpression>
  </textField>
  <staticText>
   <reportElement positionType="Float" x="0" y="25" width="500" height="30"/>
   <box>
    <pen lineWidth="0.5" lineStyle="Solid"/>
   </box>
   <textElement/>
   <text><![CDATA[ This staticText element has a positionType of "Float" ppp ]]></text>
  </staticText>

It says that when you use positionType="Float", the y attribute is ignored, because the staticText is positioned below the textField. This appears to work, BUT... is it possible they are BS'ing me? The textField has y=0 and height=24. The staticText has y=25. Coincidence? If I change the staticText's y, it is obvious that it isn't ignored: the element is positioned wherever I tell it to. There's no floating!!! Quote from the book:

As we can see, setting the positionType attribute of to Float made JasperReports ignore the y position of the element, which was pushed down by the stretched element.

No, we don't see how it is being ignored because y=25 is where we expected it! Does positionType="Float" work for staticText at all? Thanks!

+1  A: 

This answer applies (different elements, same situation).

One thing I didn't take right from the book's sample is that the textField's declared height (24) is less than the actual height when the element is stretched. So, y="25" on the staticText would map above its actual position; the element is actually floated down!

+2  A: 

My understanding of the floating nature is that the floating object will move down if necessary, but if the previous object is smaller than expected, it doesn't move up.

I don't recall having any problems with floating objects not actually floating down when necessary, whether they be static text or text fields.

On another note, if you find a text field works, you can use it to display static text by putting your text in quotes in the text field value (making it a Java object).

Jamie Love