JasperReports text field stretching - can stretch height be limited?

耗尽温柔 提交于 2019-12-02 10:16:05

问题


I've got the following problem with a JasperReports subreport that I've been trying to solve for the past couple of days with no success. Below is an image of what I'm trying to do.

I've got a subreport in one of my reports that is relatively simple. Its got a title band with a single text field (marked brown in the image) for the subreport title and a detail band with two items: a subreport (marked blue in the image) printing my line items and a text field (marked red in the image) printing the comments associated with the line items printed to the left of it. The line item subreport can print a variable number of line items (datasource backed by a bean collection). My customers requirement is that the comments field stretches and shows the text entered, but be limited by the height of the line item section (represented by the arrows on the image). I somehow need to prevent the comments from stretching beyond the line items and make them of equal height (there should be no green box in the image).

Does anyone have any tips how this could be (and can it at all be) achieved in JasperReports?

p.s. We are currently compiling our reports with JR version 3.6


回答1:


Put both the subreport and the text field into a frame. For the text field, set "Stretch with overflow" to false and "Stretch type" to "Relative to tallest object"

The text field will stretch relative to the tallest object in it's container. It's container is now the frame, so the "tallest object" can only be the subreport. Make sure the elements are the same height when you define them, otherwise they will grow at different rates.

JRXML sample:

<band height="50">
    <frame>
        <reportElement x="0" y="0" width="555" height="50"/>
        <subreport>
            <reportElement x="0" y="0" width="378" height="50"/>
            ...
        </subreport>
        <textField isStretchWithOverflow="false">
            <reportElement stretchType="RelativeToTallestObject" x="378" y="0" width="177" height="50"/>
            ...
        </textField>
    </frame> 
</band>


来源:https://stackoverflow.com/questions/8443842/jasperreports-text-field-stretching-can-stretch-height-be-limited

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