How to use positionType to pull a component up when the above component is not displayed in jasper?

三世轮回 提交于 2019-12-24 17:44:13

问题


positionType="Float" on a component pulls itself down if the above component stretches. But doesn't move up if the above component shrinks/not displayed.

Below is the version used:

<dependency>
     <groupId>net.sf.jasperreports</groupId>
     <artifactId>jasperreports-fonts</artifactId>
     <version>6.0.0</version>
</dependency>

Code that will reproduce the above issue:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="sample" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="acaa0a15-dc0f-462c-8d16-14f0b7325696">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <summary>
        <band height="500" splitType="Prevent">
            <staticText>
                <reportElement positionType="Float" x="0" y="19" width="381" height="41" isRemoveLineWhenBlank="true" uuid="9547d877-993c-4bb4-becc-cf70a0cc1bc2">
                    <printWhenExpression><![CDATA[false]]></printWhenExpression>
                </reportElement>
                <text><![CDATA[Text11111111111111111111]]></text>
            </staticText>
            <staticText>
                <reportElement positionType="Float" x="0" y="150" width="381" height="41" isRemoveLineWhenBlank="true" uuid="9e7dbe2e-2fed-41c8-82ce-c0c6886c8eda">
                    <printWhenExpression><![CDATA[true]]></printWhenExpression>
                </reportElement>
                <text><![CDATA[Text22222222222222222222]]></text>
            </staticText>
        </band>
    </summary>
</jasperReport>

Above code displays only second static text component but not first. Because the printWhenExpression in the first is false.

Now I want the second component to display in place of first, but it doesn't. As a result I'm getting space there.

How I can remove that empty space?


回答1:


From JasperReports documentation emphasize mine

positionType="Float" - The element floats in its parent section if it is pushed downward by other elements found above it. It tries to conserve the distance between it and the neighboring elements placed immediately above it.

The second reportElement will not move up to where the first reportElement is because it conserve the distance between them. The distance illustrated in image below:

Your solution is remove this space!, if you like reportElement 2 to take reportElement 1 place

Solution A

Remove the space but keep position of second reportElement if first is present. Increase height of reportElement 1.

Solution B

Remove the space by moving reportElement 2 up, if it is a textField (dynamic text) you can use isStretchWithOverflow="true" on reportElement 1 to push reportElement 2 down if reportElement 1 is overflowing.



来源:https://stackoverflow.com/questions/52032190/how-to-use-positiontype-to-pull-a-component-up-when-the-above-component-is-not-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!