Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stretch fields horizontally in jasperreport? [duplicate]

I'm using JasperReports with Eclipse Plugin in a Java project.

In JasperReports I'd like to stretch a field horizontally and move the next element to the right if the text field is too long.

Even if I set all the elements with position float nothing happens.

If I set the text field with isStretchWithOverflow="true" I get vertical stretch, like this.

enter image description here

What I'm looking for is something like this:

1   X   11111   Campo di Testo
1   X   12345678901234567890123456789012345678901234567890  Campo di Testo
like image 323
Falco Avatar asked Jan 29 '26 19:01

Falco


2 Answers

As Amongalen says in their answer there is no property to stretch horizontally.

but,

you can concatenate multiple fields in same text field to achieve your desired result.

${field1} + " " + ${field2} 

full jrxml for textField

<textField>
    <reportElement x="0" y="0" width="100" height="30" uuid="6757386c-10c7-451f-bb1a-97951697d782"/>
    <textFieldExpression><![CDATA[${field1} + " " + ${field2}]]></textFieldExpression>
</textField>
like image 200
Petter Friberg Avatar answered Feb 01 '26 09:02

Petter Friberg


As far as I know it is not possible to stretch fields horizontally.

As you can see, isStretchWithOverflow causes the field to stretch vertically only.

The other option you mention, float position refers to... well... position. If one of the field on top stretches vertically or disappears, then all field below it, with position set to float will be moved up or down accordingly.

I've tried to achieve this myself for a long time but eventually gave up, as it is most likely not possible.

In some cases, an acceptable solution would be to place multiple field with different sizes on each other. Then, based on the texts length, you show only one of them.

like image 41
Amongalen Avatar answered Feb 01 '26 08:02

Amongalen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!