How to stretch fields horizontally in jasperreport? [duplicate] - jasper-reports

This question already has answers here:
Dynamic column cell width
(3 answers)
How to stretch a text field relative to data width in Jasper Reports
(3 answers)
How to Stretch Jasper Table Columns based on Content
(1 answer)
How to increase the column width dynamically in iReport using dynamic report?
(2 answers)
Closed 3 years ago.
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.
What I'm looking for is something like this:
1 X 11111 Campo di Testo
1 X 12345678901234567890123456789012345678901234567890 Campo di Testo

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>

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.

Related

Dynamic title with ireport [duplicate]

This question already has answers here:
How to increase the column width dynamically in iReport using dynamic report?
(2 answers)
Closed 7 years ago.
I have a report done with a crosstab which makes the size of the report different according to the size of the returned results.
Thus the generated excel file can have different sizes (more or less columns), what makes the title not centered .
I want to get a title that stretches with the width of the report and gets centred accoding to the new width of the report.
I have been told that this is not possible with ireport so i wanted to make sure maybe i will find an answer .
Yes, In iReport you cannot increase the width of a component dynamically.You can only increase the height dynamically.

How to Hide lines after isPrintRepeatedValues="false" in Jasper reports

I have requirement to hide the line after setting a property isPrintRepeatedValues="false" and values is not repeated but the getting line.and check the below image and highlighted with red color arrow.
That is shouldn't come and USA will come central. Can i achive this requirement if possible?
You can use subreport for all fields exclude first field.
First field and subreport placed into frame with borders.
For first field set properties:
stretchType="RelativeToBandHeight"
verticalAlignment="Middle"
First field haven't borders.

Take sensitive frame with height of detail row

I try to border my bands in this way:
But I have a text field of my row detail with property isStretchWithOverflow="true"
In this way when I try to print my report, on the rows with overflowed text field, I've a discontinue on my border (white space instead draw line of frame).
Very simple.
I've added this property stretchType="RelativeToTallestObject" on my frame object.
So the line has not discontinuity.

Automatically stretch or shrink `<textField>` depending on text length?

I have two <textField> one by one. Is possible to automatically stretch or shrink them depending on text length? The only attribute which hit my eyes, was the isStretchWithOverflow but cause that one text is covering another - that is not what I meant. Anybody helps? Is it even possible?
I assume you are talking about stretch vertically.
In that case isStretchWithOverflow is exactly what you need.
The second <textfield> covered by first one is because the position setting. You probably has it setting to Fix, so it dose not move while first one stretched. Change the position setting of second <textfield> to Float should works.
I don't believe this is possible using pure HTML/CSS. However, you could do it by using Javascript. One way would be to bind a keypress event handler to your input which updates its width.
If you use JQuery, something like:
$(yourInput).keypress(function(){
$(this).css("width", $(this).val().length * 5);
});
should do the trick (although you'll probably want to adjust the calculation; I have no idea if 5px per character is too much or too little).

How to wrap a detail band in Jasper Reports

I have a detail band with potentially a lot of text fields in it. It can get too wide to fit on a page. The result is that it just runs off the edge of the page and you can't see it all. I'd like the detail band to wrap around to another line. Is there any way to do this?
My detail band is built dynamically in the code and the number of fields can vary. I tried manually placing the overflowing fields lower in the band by setting their y values, but then if the text in the fields overflows into two lines, my height calculations are off and the results get really messed up.
So is there any way to constrain the band to fit on the page?
Unfortunatelly, the strech types in jasper only works between bands, not within the band.
You can't (even manualy) create a jrxml which will cause a lower element in a band be correctly possitioned when an upper element overflows.
You will need to create more than one detail band. In iReport, you use 'Add another detail band' (on the detail band context-menu). Dynamically, it would look something like:
JRDesignSection detailSection = (JRDesignSection)design.getDetailSection();
JRDesignBand detail2 = new JRDesignBand();
detailSection.addBand(detail2);
Perhaps on your reportElement for each field in the band you need to set the attribute stretchType="RelativeToTallestObject".
<reportElement stretchType="RelativeToTallestObject" ...>
I'm pretty sure that's what works for me.