我真的希望有人对这个布局问题有所了解,因为我已经没有想法了。
虽然我认为我的问题与设计有关,即 Jasper 处理它们的方式(布局),但这里有一些关于应用程序的一般信息。
基本上我们有一个 JAVA 客户端-服务器应用程序,我们使用 Jasper 生成一堆报告。Jasper 设计由服务器端的 servlet 处理,并作为 jrprint 文件发送到客户端,并在客户端呈现给用户。我们还有一个 scriptlet 可以做一些事情——连接数据等。
我遇到问题的报告具有以下结构,如代码片段 #1 所示
它的数据来自一个完美运行的 SQL 查询,所以只有布局困扰着我。
在细节上,我有一堆文本字段可以可视化一些层次结构和另一个可以包含相对大量文本的文本字段。我把它们都装在一个框架中,它们都建立了另一个框架。
在它们下面我有另一个框架,可以包含 0,1 或 2 个图像(理想情况下)。我最终得到一份报告,其中包含附件 1 中的页面。
我的目标是在上面的框架和图像框架之间没有空间的报告页面 - 就像附件 2 中的那样,当然还有上框架内的文本。目前,这只有在我摆脱冗长的文本时才有可能。
在我看来,问题在于冗长文本的字段定义。由于我不知道字符串有多长,我将其定义为高度 13(代码片段 #2),即只有一行。由于字段的拉伸特性,它相应地适应,但这样做会将图像向下推可变行数。那么,有什么办法可以避免破坏设计的“推动”。
代码:
<band height="245" isSplitAllowed="false"><!-- 245 -->
<frame>
<reportElement isRemoveLineWhenBlank="true"
positionType="Float" width="545" y="0" x="0" height="75"
stretchType="RelativeToBandHeight">
</reportElement>
<box>
<pen lineColor="black" lineStyle="Solid"
lineWidth="1" />
</box>
<frame>
<reportElement isRemoveLineWhenBlank="true"
positionType="FixRelativeToTop" width="200" y="0" x="55"
height="75" stretchType="RelativeToTallestObject"/>
<box>
<pen lineColor="green" lineStyle="Solid"
lineWidth="3" />
</box>
<textField isStretchWithOverflow="true" pattern=""
isBlankWhenNull="true" evaluationGroup="Ebene2">
<reportElement x="0" y="0" width="200"
height="13" positionType="Float" isRemoveLineWhenBlank="true"
isPrintInFirstWholeBand="true">
<printWhenExpression><![CDATA[new Boolean( ($F{AnlagenEbeneOfSchaden}).intValue()==1 )]]></printWhenExpression>
</reportElement>
<textElement>
<font fontName="Arial" size="10"
isBold="true" isItalic="false" isUnderline="false"
isStrikeThrough="false" pdfFontName="Helvetica-Bold"
pdfEncoding="CP1252" isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[((alwin2Scriptlet)$P{REPORT_SCRIPTLET}).getStrukturBezMitStandOrtEbeneDB($F{Strukturcode1}, 1)]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern=""
isBlankWhenNull="true" evaluationGroup="Ebene2">
<reportElement x="15" y="0" width="185"
height="13" mode="Opaque" positionType="Float"
isRemoveLineWhenBlank="true" isPrintInFirstWholeBand="true" />
<textElement>
<font fontName="Arial" size="10"
isBold="true" isItalic="false" isUnderline="false"
isStrikeThrough="false" pdfFontName="Helvetica-Bold"
pdfEncoding="CP1252" isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[((alwin2Scriptlet)$P{REPORT_SCRIPTLET}).getStrukturBezMitStandOrtEbeneDB($F{Strukturcode1}, 2)]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern=""
isBlankWhenNull="true" evaluationGroup="Ebene3">
<reportElement mode="Opaque" x="30" y="15"
width="170" height="13" positionType="Float"
isRemoveLineWhenBlank="true" />
<textElement>
<font fontName="Arial" size="10"
isBold="false" isItalic="false" isUnderline="false"
isStrikeThrough="false" pdfFontName="Helvetica"
pdfEncoding="CP1252" isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[((alwin2Scriptlet)$P{REPORT_SCRIPTLET}).getStrukturBezMitStandOrtEbeneDB($F{Strukturcode1}, 3)]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern=""
isBlankWhenNull="true">
<reportElement mode="Opaque" x="45" y="30"
width="155" height="13" positionType="Float"
isRemoveLineWhenBlank="true" />
<textElement>
<font fontName="Arial" size="10"
isBold="false" isItalic="false" isUnderline="false"
isStrikeThrough="false" pdfFontName="Helvetica"
pdfEncoding="CP1252" isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[((alwin2Scriptlet)$P{REPORT_SCRIPTLET}).getStrukturBezMitStandOrtEbeneDB($F{Strukturcode1}, 4)]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern=""
isBlankWhenNull="true">
<reportElement mode="Opaque" x="60" y="45"
width="140" height="13" positionType="Float"
isRemoveLineWhenBlank="true" />
<textElement>
<font fontName="Arial" size="10"
isBold="false" isItalic="false" isUnderline="false"
isStrikeThrough="false" pdfFontName="Helvetica"
pdfEncoding="CP1252" isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[((alwin2Scriptlet)$P{REPORT_SCRIPTLET}).getStrukturBezMitStandOrtEbeneDB($F{Strukturcode1}, 5)]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern=""
isBlankWhenNull="true">
<reportElement mode="Opaque" x="75" y="60"
width="125" height="13" positionType="Float"
isRemoveLineWhenBlank="true" />
<textElement>
<font fontName="Arial" size="10"
isBold="false" isItalic="false" isUnderline="false"
isStrikeThrough="false" pdfFontName="Helvetica"
pdfEncoding="CP1252" isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[((alwin2Scriptlet)$P{REPORT_SCRIPTLET}).getStrukturBezMitStandOrtEbeneDB($F{Strukturcode1}, 6)]]></textFieldExpression>
</textField>
</frame>
<textField isStretchWithOverflow="true" pattern=""
isBlankWhenNull="true">
<reportElement mode="Opaque" x="30" y="1" width="20"
height="13" isRemoveLineWhenBlank="true" />
<textElement>
<font fontName="Arial" size="10" isBold="true"
isItalic="false" isUnderline="false" isStrikeThrough="false"
pdfFontName="Helvetica" pdfEncoding="CP1252"
isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern=""
isBlankWhenNull="true">
<reportElement mode="Opaque" x="515" y="1"
width="20" height="13" isRemoveLineWhenBlank="true" />
<textElement textAlignment="Right">
<font fontName="Arial" size="11" isBold="true"
isItalic="false" isUnderline="false" isStrikeThrough="false"
pdfFontName="Helvetica-Bold" pdfEncoding="CP1252"
isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Bewertung}]]></textFieldExpression>
</textField>
<frame>
<reportElement isRemoveLineWhenBlank="true"
positionType="FixRelativeToTop" width="240" y="0" x="255"
height="15" stretchType="RelativeToTallestObject" />
<box>
<pen lineColor="red" lineStyle="Solid"
lineWidth="3" />
</box>
<textField isStretchWithOverflow="true"
isBlankWhenNull="true">
<reportElement mode="Opaque" x="0" y="1"
width="240" height="13" isRemoveLineWhenBlank="true"
isPrintWhenDetailOverflows="true" />
<textElement verticalAlignment="Top">
<font fontName="Arial" size="10"
isBold="false" isItalic="false" isUnderline="false"
isStrikeThrough="false" pdfFontName="Helvetica"
pdfEncoding="CP1252" isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{SCHADENGRUPPE} + ($F{SCHADENBESCHREIBUNG}!=null?$F{SCHADENBESCHREIBUNG}:"")+" ["+$F{SCHADENNR}+"]"]]></textFieldExpression>
</textField>
</frame>
</frame>
<frame>
<reportElement isRemoveLineWhenBlank="true"
positionType="Float" width="545" y="76" x="0" height="155">
<printWhenExpression><![CDATA[new Boolean( (!($F{BILD1_FILE} == null) ) || (!($F{BILD2_FILE} == null)) )]]></printWhenExpression>
</reportElement>
<!-- <box padding="5">
<pen lineColor="black" lineStyle="Solid"
lineWidth="3" />
</box>
-->
<image vAlign="Top" hAlign="Center">
<reportElement positionType="Float" x="303" y="0"
width="212" height="145" isPrintWhenDetailOverflows="true"
isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new Boolean( (!($F{BILD1_FILE} == null) ) && ($F{BILD2_FILE} == null) )]]></printWhenExpression>
</reportElement>
<graphicElement />
<imageExpression class="java.awt.Image"><![CDATA[$F{BILD1_FILE}]]></imageExpression>
</image>
<image vAlign="Top" hAlign="Center">
<reportElement positionType="Float" x="303" y="0"
width="212" height="145" isPrintWhenDetailOverflows="true"
isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new Boolean( (!($F{BILD2_FILE} == null)) && ($F{BILD1_FILE} == null) )]]></printWhenExpression>
</reportElement>
<graphicElement />
<imageExpression class="java.awt.Image"><![CDATA[$F{BILD2_FILE}]]></imageExpression>
</image>
<image vAlign="Top" hAlign="Center">
<reportElement positionType="Float" x="70" y="0"
width="212" height="145" isPrintWhenDetailOverflows="true"
isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new Boolean( (!($F{BILD1_FILE} == null) ) && (!($F{BILD2_FILE} == null)) )]]></printWhenExpression>
</reportElement>
<graphicElement />
<imageExpression class="java.awt.Image"><![CDATA[$F{BILD1_FILE}]]></imageExpression>
</image>
<image vAlign="Top" hAlign="Center">
<reportElement positionType="Float" x="303" y="0"
width="212" height="145" isPrintWhenDetailOverflows="true"
isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new Boolean( (!($F{BILD2_FILE} == null)) && (!($F{BILD1_FILE} == null)) )]]></printWhenExpression>
</reportElement>
<graphicElement />
<imageExpression class="java.awt.Image"><![CDATA[$F{BILD2_FILE}]]></imageExpression>
</image>
</frame>
<line>
<reportElement positionType="Float" mode="Opaque" x="0"
y="240" width="525" height="1" />
<graphicElement pen="Thin" />
</line>
<!--
<frame>
<reportElement isRemoveLineWhenBlank="true"
positionType="Float" width="545" y="86" x="0" height="170">
<printWhenExpression><![CDATA[new Boolean( (!($F{BILD1_FILE} == null) ) || (!($F{BILD2_FILE} == null)) )]]></printWhenExpression>
</reportElement>
<box>
<pen lineColor="black" lineStyle="Solid"
lineWidth="1" />
</box>
</frame>
-->
</band>
代码:
<textField isStretchWithOverflow="true"
isBlankWhenNull="true">
<reportElement mode="Opaque" x="0" y="1"
width="240" height="13" isRemoveLineWhenBlank="true"
isPrintWhenDetailOverflows="true" />
<textElement verticalAlignment="Top">
<font fontName="Arial" size="10"
isBold="false" isItalic="false" isUnderline="false"
isStrikeThrough="false" pdfFontName="Helvetica"
pdfEncoding="CP1252" isPdfEmbedded="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{SCHADENGRUPPE} + ($F{SCHADENBESCHREIBUNG}!=null?$F{SCHADENBESCHREIBUNG}:"")+" ["+$F{SCHADENNR}+"]"]]></textFieldExpression>
</textField>