如何在Jasper报告中组织框架,使它们完美无瑕地漂浮? [英] How to organize Frames in Jasper Report so they float flawlessly?

查看:190
本文介绍了如何在Jasper报告中组织框架,使它们完美无瑕地漂浮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jasper报告中,我有4个帧(图像下方),其中一些属性设置如同一个图像所示。





这是



使用父框架的示例



jrxml

 <?xml version =1.0encoding =UTF-8?> 
< jasperReport xmlns =http://jasperreports.sourceforge.net/jasperreportsxmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http: //jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsdname =Float_UPpageWidth =595pageHeight =842columnWidth =555leftMargin =20 rightMargin =20topMargin =20bottomMargin =20uuid =6578bc34-0c2e-4179-99da-5ec1dd90a422>
< property name =com.jaspersoft.studio.data.defaultdataadaptervalue =One Empty Record/>
< parameter name =showBlueclass =java.lang.Boolean/>
< parameter name =showRedclass =java.lang.Boolean/>
< queryString>
<![CDATA []]>
< / queryString>
< detail>
< band height =96splitType =Stretch>
< staticText>
< reportElement x =0y =0width =400height =12uuid =54cb1704-59d8-4272-9ec1-db4cea913cd3/>
< text><![CDATA [标题1(在条件框架之前)]]>< / text>
< / staticText>
< frame>
< reportElement x =0y =15width =409height =78uuid =82076f1d-b7a9-4b63-ab4a-af54b0817a62/>
< frame>
< reportElement x =0y =4width =400height =66isRemoveLineWhenBlank =trueuuid =0140ba9b-f2f0-494c-82bc-caf6b5efc63e>
< printWhenExpression><![CDATA [$ P {showBlue}]]>< / printWhenExpression>
< / reportElement>
< box>
< pen lineWidth =3.0lineColor =#2E0DD4/>
< / box>
< staticText>
< reportElement x =1y =1width =379height =59uuid =a8b7d505-a6ad-4359-9263-23ac087b19ff/>
< textElement>
< font size =14/>
< / textElement>
< text><![CDATA [BLUE:`isRemoveLineWhenBlank = true`和`printWhenExpression` set]]>< / text>
< / staticText>
< / frame>
< frame>
< reportElement positionType =Floatx = - 1y =75width =400height =60isRemoveLineWhenBlank =trueuuid =c80dd879-ce81-4921-b17e-9882763a3f61 >
< printWhenExpression><![CDATA [$ P {showRed}]]>< / printWhenExpression>
< / reportElement>
< box>
< pen lineWidth =3.0lineColor =#F50A25/>
< / box>
< staticText>
< reportElement x =0y =0width =380height =50uuid =d0cadbd4-b436-47f4-a32d-2b00f0c6b147/>
< textElement>
< font size =14/>
< / textElement>
< text><![CDATA [RED:`isRemoveLineWhenBlank = true`,`printWhenExpression` set和`positionType =Float`]]>< / text>
< / staticText>
< / frame>
< frame>
< reportElement positionType =Floatx =0y =140width =398height =60uuid =e0a5ed13-d8f2-4acd-ac14-1f5633099542/>
< box>
< pen lineWidth =3.0lineColor =#22B002/>
< / box>
< staticText>
< reportElement x =1y =1width =377height =39uuid =482471b4-4c3b-42c6-892d-f8c42ca320bf/>
< textElement>
< font size =14/>
< / textElement>
< text><![CDATA [GREEN:`positionType =Float`]]>< / text>
< / staticText>
< / frame>
< / frame>
< frame>
< reportElement x =420y =15width =130height =70uuid =8e057d80-72be-4f66-ae9b-ef80610daf36/>
< box>
< pen lineWidth =3.0/>
< / box>
< staticText>
< reportElement x =6y =6width =118height =44uuid =36d8e560-3af5-4edf-b9ef-9b9311877c3a/>
< textElement>
< font size =14/>
< / textElement>
< text><![CDATA [BLACK]]>< / text>
< / staticText>
< / frame>
< / band>
< / detail>
< / jasperReport>

输出





其他设计说明



正如您在输出中看到的那样,绿色和黑色框之间存在4px的高度差异,这是由于帧之间存在空白空间。如果您需要像素完美报告,则需要在要移除/浮动的组件之间零空间


In a Jasper report I have 4 Frames (below image) which have some properties set as shown in the same image.

Now, the idea is that given certain parameters showBlue and showRed the frames BLUE and RED respectively are shown or hidden and the subsequent frame "floats" after the previous one (taking in consideration the following order: BLUE <- RED <- GREEN) while BLACK should stay in the same place.

The two left frames (RED and GREEN) were floating up perfectly before the BLACK one was set in place. After that when I set the parameters showBlue and showRed to false (hide BLUE and RED frames) this is the result:

This is the jrxml for the report design:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1  -->
<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="Float_UP" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6578bc34-0c2e-4179-99da-5ec1dd90a422">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <parameter name="showBlue" class="java.lang.Boolean"/>
    <parameter name="showRed" class="java.lang.Boolean"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <detail>
        <band height="211" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="400" height="12" uuid="54cb1704-59d8-4272-9ec1-db4cea913cd3"/>
                <text><![CDATA[Header 1 (right before conditional frame)]]></text>
            </staticText>
            <frame>
                <reportElement x="0" y="15" width="400" height="66" isRemoveLineWhenBlank="true" uuid="0140ba9b-f2f0-494c-82bc-caf6b5efc63e">
                    <printWhenExpression><![CDATA[$P{showBlue}]]></printWhenExpression>
                </reportElement>
                <box>
                    <pen lineWidth="3.0" lineColor="#2E0DD4"/>
                </box>
                <staticText>
                    <reportElement x="1" y="1" width="379" height="59" uuid="a8b7d505-a6ad-4359-9263-23ac087b19ff"/>
                    <textElement>
                        <font size="14"/>
                    </textElement>
                    <text><![CDATA[BLUE: `isRemoveLineWhenBlank=true` and `printWhenExpression` set]]></text>
                </staticText>
            </frame>
            <frame>
                <reportElement positionType="Float" x="0" y="85" width="400" height="60" isRemoveLineWhenBlank="true" uuid="c80dd879-ce81-4921-b17e-9882763a3f61">
                    <printWhenExpression><![CDATA[$P{showRed}]]></printWhenExpression>
                </reportElement>
                <box>
                    <pen lineWidth="3.0" lineColor="#F50A25"/>
                </box>
                <staticText>
                    <reportElement x="0" y="0" width="380" height="50" uuid="d0cadbd4-b436-47f4-a32d-2b00f0c6b147"/>
                    <textElement>
                        <font size="14"/>
                    </textElement>
                    <text><![CDATA[RED: `isRemoveLineWhenBlank=true`, `printWhenExpression` set and `positionType="Float"`]]></text>
                </staticText>
            </frame>
            <frame>
                <reportElement positionType="Float" x="2" y="151" width="398" height="60" uuid="e0a5ed13-d8f2-4acd-ac14-1f5633099542"/>
                <box>
                    <pen lineWidth="3.0" lineColor="#22B002"/>
                </box>
                <staticText>
                    <reportElement x="1" y="1" width="377" height="39" uuid="482471b4-4c3b-42c6-892d-f8c42ca320bf"/>
                    <textElement>
                        <font size="14"/>
                    </textElement>
                    <text><![CDATA[GREEN: `positionType="Float"`]]></text>
                </staticText>
            </frame>
            <frame>
                <reportElement x="420" y="15" width="130" height="70" uuid="8e057d80-72be-4f66-ae9b-ef80610daf36"/>
                <box>
                    <pen lineWidth="3.0"/>
                </box>
                <staticText>
                    <reportElement x="6" y="6" width="118" height="44" uuid="36d8e560-3af5-4edf-b9ef-9b9311877c3a"/>
                    <textElement>
                        <font size="14"/>
                    </textElement>
                    <text><![CDATA[BLACK]]></text>
                </staticText>
            </frame>
        </band>
    </detail>
</jasperReport>

And I have set up a Java Project with Swagger in case you want to run it with maven.

Q: How can I make frames RED and GREEN to properly "float-up" after its previous frame while frame BLACK stays in the same place?

解决方案

Yes the green will not float up since the black box is placed immediately above it

From JRElement API

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

Solution

The solutions obviously is to not have any element immediately above it and one way to achieve this is to use another frame or a subreport. If you need elements to float up also under this design you probably will need a subreport but I will show the parent frame solution, because it is the easiest way to solve your direct problem.

Example using a parent frame

jrxml

<?xml version="1.0" encoding="UTF-8"?>
<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="Float_UP" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6578bc34-0c2e-4179-99da-5ec1dd90a422">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <parameter name="showBlue" class="java.lang.Boolean"/>
    <parameter name="showRed" class="java.lang.Boolean"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <detail>
        <band height="96" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="400" height="12" uuid="54cb1704-59d8-4272-9ec1-db4cea913cd3"/>
                <text><![CDATA[Header 1 (right before conditional frame)]]></text>
            </staticText>
            <frame>
                <reportElement x="0" y="15" width="409" height="78" uuid="82076f1d-b7a9-4b63-ab4a-af54b0817a62"/>
                <frame>
                    <reportElement x="0" y="4" width="400" height="66" isRemoveLineWhenBlank="true" uuid="0140ba9b-f2f0-494c-82bc-caf6b5efc63e">
                        <printWhenExpression><![CDATA[$P{showBlue}]]></printWhenExpression>
                    </reportElement>
                    <box>
                        <pen lineWidth="3.0" lineColor="#2E0DD4"/>
                    </box>
                    <staticText>
                        <reportElement x="1" y="1" width="379" height="59" uuid="a8b7d505-a6ad-4359-9263-23ac087b19ff"/>
                        <textElement>
                            <font size="14"/>
                        </textElement>
                        <text><![CDATA[BLUE: `isRemoveLineWhenBlank=true` and `printWhenExpression` set]]></text>
                    </staticText>
                </frame>
                <frame>
                    <reportElement positionType="Float" x="-1" y="75" width="400" height="60" isRemoveLineWhenBlank="true" uuid="c80dd879-ce81-4921-b17e-9882763a3f61">
                        <printWhenExpression><![CDATA[$P{showRed}]]></printWhenExpression>
                    </reportElement>
                    <box>
                        <pen lineWidth="3.0" lineColor="#F50A25"/>
                    </box>
                    <staticText>
                        <reportElement x="0" y="0" width="380" height="50" uuid="d0cadbd4-b436-47f4-a32d-2b00f0c6b147"/>
                        <textElement>
                            <font size="14"/>
                        </textElement>
                        <text><![CDATA[RED: `isRemoveLineWhenBlank=true`, `printWhenExpression` set and `positionType="Float"`]]></text>
                    </staticText>
                </frame>
                <frame>
                    <reportElement positionType="Float" x="0" y="140" width="398" height="60" uuid="e0a5ed13-d8f2-4acd-ac14-1f5633099542"/>
                    <box>
                        <pen lineWidth="3.0" lineColor="#22B002"/>
                    </box>
                    <staticText>
                        <reportElement x="1" y="1" width="377" height="39" uuid="482471b4-4c3b-42c6-892d-f8c42ca320bf"/>
                        <textElement>
                            <font size="14"/>
                        </textElement>
                        <text><![CDATA[GREEN: `positionType="Float"`]]></text>
                    </staticText>
                </frame>
            </frame>
            <frame>
                <reportElement x="420" y="15" width="130" height="70" uuid="8e057d80-72be-4f66-ae9b-ef80610daf36"/>
                <box>
                    <pen lineWidth="3.0"/>
                </box>
                <staticText>
                    <reportElement x="6" y="6" width="118" height="44" uuid="36d8e560-3af5-4edf-b9ef-9b9311877c3a"/>
                    <textElement>
                        <font size="14"/>
                    </textElement>
                    <text><![CDATA[BLACK]]></text>
                </staticText>
            </frame>
        </band>
    </detail>
</jasperReport>

Output

Additional design notes

As you can see in output there is a 4px height difference between the green and black box, this is due to the empty space you have between the frames. If you need pixel perfect reports you need to have zero space between the components that you are removing/floating.

这篇关于如何在Jasper报告中组织框架,使它们完美无瑕地漂浮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆