8

我需要有一个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>

它说,当您使用y 时positionType="Float",将忽略 y 属性,因为staticText位于textField. 这似乎可行,但是……他们有可能在骂我吗?有textFieldy=0 和 height=24。有staticTexty=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?谢谢!

4

2 回答 2

6

我对浮动性质的理解是,如果需要,浮动对象会向下移动,但如果之前的对象小于预期,它不会向上移动。

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

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

于 2008-12-23T03:21:25.857 回答
5

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!

于 2008-12-11T12:02:39.870 回答