Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stretch a text field relative to data width in Jasper Reports

I have a text field followed by a static text field and I am trying to do 2 things with it:

  1. Get the text field to stretch horizontally (not wrap) when text is longer then the field width and
  2. Push the static text field right when the text field to the left of it stretches

Both of the fields are contained within a frame.

I have both fields set to positionType=float and the text field set to stretchWithOverflow=true, which enable text to wrap vertically but not stretch horizontally.

Is it possible to achieve 1 and 2 above? If so How?

like image 827
travega Avatar asked Jan 23 '12 21:01

travega


People also ask

How do I stretch text field in Jasper report?

Click on the particular textfield in iReport. On the right side, see TextField properties. Check the option "STRETCH WITH OVERFLOW".

What is stretch type in Jasper report?

The stretchType attribute of a report element can be used to customize the stretch behavior of the element when the enclosing report section stretches itself according to the text fields which stretch themselves.

How do I align text in Jasper report?

Select the text filed, select "Properties" tab and select center icon in the "Text Alignment". Vote up!


2 Answers

Instead of having 2 text fields (dynamic and static), you can have 1 text field with value as $F{Field} + "statix text". This will probably fix your issue. Also, you can set the "width" and "stretch with overflow" properties, as per your requirements.

like image 176
bchetty Avatar answered Sep 17 '22 13:09

bchetty


Well it's bad news!! According to Jaspersoft's documentation on stretching fields it is not possible to stretch the width of a field:

"Usually, the stretching process refers to the height adjustment only. When stretching report elements, adjusting the width could affect also the page width and raise unexpected errors at runtime (for instance, truncated information could be printed out on pages). This is why stretching an element let its width unchanged, while its height gets definitely enlarged in order to make room for all information that have to be displayed." (Jaspersoft documentation [v4.5.0], 2011)

However a solution to the original issue can be found here thanks to @mdahlman

like image 22
travega Avatar answered Sep 19 '22 13:09

travega