Jasper Reports - align dynamic text fields and their labels horizontally

前端 未结 4 1710
一整个雨季
一整个雨季 2020-12-02 13:34

I\'m using Jasper report 5.2, iReport 5.2 and exporting the report in RTF and PDF formats.

In my report I want to add few text fields along with their (static text)l

4条回答
  •  星月不相逢
    2020-12-02 14:19

    It can be easily done with help of container - the Frame element.

    You should put Frame with Position Type as Float and put to them both staticText (label) and textField.

    For textField I've set Position Type as Float the Stretch With Overlfow as true.

    The sample

    The jrxml file:

    
    
        
        
        
        
            <band height="69" splitType="Stretch">
                <frame>
                    <reportElement uuid="314bfd5b-7b0a-42f4-aca3-e61f0283f126" positionType="Float" x="213" y="1" width="243" height="20"/>
                    <staticText>
                        <reportElement uuid="e07201bb-a677-4dc9-a332-f94e6eca2722" positionType="Float" x="0" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <text><![CDATA[Name]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="true">
                        <reportElement uuid="66c93a44-9015-4ae9-bf05-b68b2420f3ef" positionType="Float" x="121" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{name}]]></textFieldExpression>
                    </textField>
                </frame>
                <frame>
                    <reportElement uuid="8311a483-955e-4280-a9ac-513d7d34495b" positionType="Float" x="213" y="21" width="243" height="20"/>
                    <staticText>
                        <reportElement uuid="da404b4e-7908-40ae-8e1b-38e19d9ddc7f" positionType="Float" x="0" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <text><![CDATA[ID]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="true">
                        <reportElement uuid="e0e312e8-cd2f-48af-8ae8-df95c6195488" positionType="Float" x="121" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{id}]]></textFieldExpression>
                    </textField>
                </frame>
                <frame>
                    <reportElement uuid="8ff2baf9-b0ec-4c8a-b54a-9edd08b200cc" positionType="Float" x="213" y="41" width="243" height="20"/>
                    <staticText>
                        <reportElement uuid="b8d97db0-250a-43c8-a2f3-2fa3668c5d15" positionType="Float" x="0" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <text><![CDATA[Date]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="true">
                        <reportElement uuid="4daa4d17-28be-4ac8-8e1e-2efbeec5f690" positionType="Float" x="121" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
                    </textField>
                </frame>
            </band>
        
    
    

    The report's design in iReport:

    enter image description here

    The result will be (via iReport preview):

    enter image description here

提交回复
热议问题