如何在JasperReports中删除textfield之间的额外空间? [英] How to remove extra space between textfield in JasperReports?

查看:97
本文介绍了如何在JasperReports中删除textfield之间的额外空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Header中创建了三个文本字段。我已将参数放在所有 textField 元素中。当我没有调用三个 textField 元素的三个参数之一时。它将显示2 textField 元素。现在的问题是文本字段之间有空格。

I have created three text field in Header. I have put parameter in all textField elements. When I'm not calling one of three parameter of three textField elements. It will show 2 textField elements. The problem now is there are space between the text fields.

如何删除空格?

这是我的代码:

<textField isBlankWhenNull="true">
    <reportElement x="0" y="18" width="555" height="35" isRemoveLineWhenBlank="true"/>
    <textElement textAlignment="Center">
        <font size="12"/>
    </textElement>
    <textFieldExpression><![CDATA[$P{daterangefrom}  && $P{daterangeto}  ?  "From ( " + $P{daterangefrom} + " - " + $P{daterangeto} + ")"
: $P{weeks}  && $P{monthy} && $P{yrs} ? "For week " + $P{weeks} +" "+ $P{monthy} +" "+ $P{yrs}
: $P{monthy}  && $P{yrs} ? "For monthly " +$P{monthy} +" "+ $P{yrs}
: $P{quarter}  &&  $P{yrs}  ? "For Quarter " + $P{quarter} +" "+$P{yrs}
: $P{yrs}  ? "For " + $P{yrs}
: null]]>
    </textFieldExpression>
</textField>

这是我的结果:

< img src =https://i.stack.imgur.com/gpE6j.jpgalt =在此输入图像说明>

推荐答案

您可以使用3 textField 元素 isRemoveLineWhenBlank 属性设置为 true value。

You can use 3 textField elements with isRemoveLineWhenBlank property set to true value.

示例(jrxml文件):

The sample (jrxml file):

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport .. topMargin="0" bottomMargin="0">
    <parameter name="parameter1" class="java.lang.String">
        <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
    </parameter>
    <parameter name="parameter2" class="java.lang.String">
        <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
    </parameter>
    <parameter name="parameter3" class="java.lang.String">
        <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
    </parameter>
    <title>
        <band height="102" splitType="Stretch">
            <textField isBlankWhenNull="true">
                <reportElement x="163" y="9" width="100" height="20" isRemoveLineWhenBlank="true"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{parameter1} == null ? null : "Parameter1: " + $P{parameter1}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="163" y="29" width="100" height="20" isRemoveLineWhenBlank="true"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{parameter2} == null ? null : "Parameter2: " + $P{parameter2}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="163" y="49" width="100" height="20" isRemoveLineWhenBlank="true"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{parameter3} == null ? null : "Parameter3: " + $P{parameter3}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="163" y="73" width="100" height="20"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <text><![CDATA[Static text]]></text>
            </staticText>
            <line>
                <reportElement x="63" y="6" width="447" height="1"/>
            </line>
            <line>
                <reportElement x="73" y="96" width="447" height="1"/>
            </line>
        </band>
    </title>
</jasperReport>

iReport 中的报表设计:

The report design in iReport:

对于 parameter1 = null,parameter2 = null,parameter1 = value3 结果将是:

For the parameter1=null, parameter2=null, parameter1=value3 the result will be:

更新

UPDATE

为解决上移 textField 的问题,如果上面的元素被隐藏,你可以使用 框架 容器。您应该添加2个帧(每列一个)并在每个帧中放置2个 textField 元素(2行)。

For solving the problem of moving up the textField in case the element above was hide you can use the Frame container. You should add 2 frames (one per column) and put 2 textField elements (2 rows) in each frame.

样本(jrxml文件):

The sample (jrxml file):

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport .. topMargin="0" bottomMargin="0">
    <parameter name="par1" class="java.lang.String">
        <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
    </parameter>
    <parameter name="par2" class="java.lang.String">
        <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
    </parameter>
    <parameter name="par3" class="java.lang.String">
        <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
    </parameter>
    <parameter name="par4" class="java.lang.String">
        <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
    </parameter>
    <title>
        <band height="80" splitType="Stretch">
            <line>
                <reportElement x="10" y="6" width="520" height="1"/>
            </line>
            <line>
                <reportElement x="10" y="72" width="520" height="1"/>
            </line>
            <frame>
                <reportElement x="329" y="10" width="172" height="59"/>
                <frame>
                    <reportElement x="13" y="3" width="60" height="54"/>
                    <textField isBlankWhenNull="true">
                        <reportElement x="1" y="20" width="52" height="20" isRemoveLineWhenBlank="true"/>
                        <box>
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{par3} == null ? null : "P3: " + $P{par3}]]></textFieldExpression>
                    </textField>
                    <textField isBlankWhenNull="true">
                        <reportElement x="1" y="0" width="52" height="20" isRemoveLineWhenBlank="true"/>
                        <box>
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{par1} == null ? null : "P1: " + $P{par1}]]></textFieldExpression>
                    </textField>
                </frame>
                <frame>
                    <reportElement x="73" y="3" width="70" height="54"/>
                    <textField isBlankWhenNull="true">
                        <reportElement x="1" y="0" width="52" height="20" isRemoveLineWhenBlank="true"/>
                        <box>
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{par2} == null ? null : "P2: " + $P{par2}]]></textFieldExpression>
                    </textField>
                    <textField isBlankWhenNull="true">
                        <reportElement x="1" y="20" width="52" height="20" isRemoveLineWhenBlank="true"/>
                        <box>
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{par4} == null ? null : "P4: " + $P{par4}]]></textFieldExpression>
                    </textField>
                </frame>
            </frame>
            <textField isBlankWhenNull="true">
                <reportElement x="10" y="30" width="52" height="20" isRemoveLineWhenBlank="true"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{par3} == null ? null : "P3: " + $P{par3}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="10" y="10" width="52" height="20" isRemoveLineWhenBlank="true"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{par1} == null ? null : "P1: " + $P{par1}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="64" y="10" width="52" height="20" isRemoveLineWhenBlank="true"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{par2} == null ? null : "P2: " + $P{par2}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="64" y="30" width="52" height="20" isRemoveLineWhenBlank="true"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{par4} == null ? null : "P4: " + $P{par4}]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

iReport 中的报表设计:

The report design in iReport:

对于 par1 = null,par2 = 2,par3 = 3,par4 = 4 ,结果将为:

For the par1=null, par2=2, par3=3, par4=4 the result will be:

您可以比较结果 - 左侧不使用框架,右侧有 框架 元素。

You can compare the results - left side is done without using frame and the right side with frame elements.

这篇关于如何在JasperReports中删除textfield之间的额外空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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