JasperReports:对于staticText,positionType =''Float'的工作是什么?

6 jasper-reports

我需要一个staticText浮动到另一个具有可变高度的元素下面.我正在拿书中的样本JasperReports for Java Programmers.它说可以做到这一点.与我的示例的不同之处在于我使用了硬编码字符串textFieldExpression,它们使用$ F {}字段.

<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>
Run Code Online (Sandbox Code Playgroud)

它表示当你使用时positionType="Float",y属性被忽略,因为staticText它位于textField.这似乎有效,但是......他们可能是我的BS吗?所述textField具有Y = 0和高度= 24.所述staticText具有Y = 25.巧合?如果我更改了staticText'sy',很明显它不会被忽略:元素位于我告诉它的任何地方.没有漂浮!!! 从书中引用:

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

不,我们不知道它是如何被忽略的,因为y = 25是我们所期望的!是否positionType="Float"对工作的staticText呢?谢谢!

Jam*_*ove 6

我对浮动特性的理解是,如果需要,浮动对象将向下移动,但如果前一个对象小于预期,则它不会向上移动.

我不记得在必要时浮动对象实际上没有浮动的任何问题,无论它们是静态文本还是文本字段.

另一方面,如果您发现文本字段有效,则可以通过将文本放在文本字段值中的引号(使其成为Java对象)来使用它来显示静态文本.


小智 5

这个答案适用(不同的元素,相同的情况)。

我没有从书中的示例中得到的一件事是,textField 声明的高度 (24) 小于元素拉伸时的实际高度。因此,staticText 上的 y="25" 将映射到其实际位置之上;元素实际上是向下浮动的!