Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

jasper reports - How to draw a border around both the column header, footer and detail sections?

I have a requirement to have a border that will encapsulate all the details + the column header in a report made in JasperReports + iReport. But if I try to draw a rect or a frame that goes in both the columns header, the details and column footer, I get an error saying that the element position is invalid.

I guess one option would be to use images (just like the good old HTML times without CSS...) but it would be a PITA since if a field overflow or if someone change the height or the width of a section, the image will have to change...

Any other alternatives?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To do this you can put frames into each of the bands, setting their size to fill the band completely. Then set the borders on the frames to replicate a border around all three bands, so the header has a border at the top, left and right; the footer has bottom, left and right; and the detail band has a border only on the left and right. See the example code below.

<columnHeader>
    <band height="61" splitType="Stretch">
        <frame>
            <reportElement x="0" y="0" width="555" height="61"/>
            <box>
                <topPen lineWidth="2.0" lineStyle="Solid"/>
                <leftPen lineWidth="2.0" lineStyle="Solid"/>
                <rightPen lineWidth="2.0" lineStyle="Solid"/>
            </box>
        </frame>
    </band>
</columnHeader>
<detail>
    <band height="125" splitType="Stretch">
        <frame>
            <reportElement x="0" y="0" width="555" height="125"/>
            <box>
                <leftPen lineWidth="2.0" lineStyle="Solid"/>
                <rightPen lineWidth="2.0" lineStyle="Solid"/>
            </box>
        </frame>
    </band>
</detail>
<columnFooter>
    <band height="45" splitType="Stretch">
        <frame>
            <reportElement x="0" y="0" width="555" height="45"/>
            <box>
                <leftPen lineWidth="2.0" lineStyle="Solid"/>
                <bottomPen lineWidth="2.0" lineStyle="Solid"/>
                <rightPen lineWidth="2.0" lineStyle="Solid"/>
            </box>
        </frame>
    </band>
</columnFooter>

The result should look like this: Screenshot from iReport


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...