JasperReports: paddings misbehave in table body cells - jasper-reports

I have a problem with correctly setting paddings in JasperReports tables.
I'm using styles to uniformly configure text boxes of the same purpose, eg. for displaying currency. However, the paddings behave differently in text fields in table body and table footer. Inside the table, the top and bottom padding works correcly, however, left and right not. The 2 pixels are ignored, so I'd have to use 4 to get 2.
In table footer, paddings work normally, which makes numbers misaligned. But the whole footer cell looks to be shifted.
This is my JRXML fragment:
<jr:tableFooter style="Table_TH" height="16" rowSpan="1">
<textField>
<reportElement style="Custom_Currency" x="0" y="0" width="105" height="16" isRemoveLineWhenBlank="true"/>
<textFieldExpression><![CDATA[$P{taxTotal}]]></textFieldExpression>
</textField>
</jr:tableFooter>
<jr:detailCell style="Table_TD" height="16">
<textField>
<reportElement style="Custom_Currency" x="0" y="0" width="105" height="16" />
<textFieldExpression><![CDATA[$F{tax}]]></textFieldExpression>
</textField>
</jr:detailCell>
<style name="Custom_Text" mode="Opaque" backcolor="#EBEBEB" pattern="" isBlankWhenNull="true" fontSize="8">
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</style>
<style name="Custom_Currency" style="DF_Text" hTextAlign="Right" pattern="#,##0.00">
<box topPadding="2" leftPadding="4" bottomPadding="2" rightPadding="4"/>
</style>
and this is how it looks in action:
How should I declare paddings so that they work consistently in my whole report?

Related

Hidden property when exporting JasperReport

I want to hide a text field using jasper report so when i will view it in html i wont see its content, but the problem is that it has to be there (proggram JAWS has to read it) so i can't use "printWhenExpression". I tried to use width properties to hide it but so far i have no effect.
<textField>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
If I understood correctly, you need to keep the shape of the box as if the content was here, but you want the content to disappear.
It's true that printWhenExpression will make the whole item disappear.
You can either :
Use a parent item such as a frame to be around the textField, so printWhenExpression is true on the text fields, then the frame will still be here to keep its place.
<frame>
<reportElement x="0" y="0" width="200" height="200" uuid="25b397bf-e718-43ab-8641-4f7c7932253f"/>
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="4e8ea258-88f0-4220-a350-448da63390d1">
<printWhenExpression><![CDATA[the_condition]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</frame>
Use a java condition in your text field. If the condition is false, the text will disappear but the text field frame will still be displayed.
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="4e8ea258-88f0-4220-a350-448da63390d1">
<printWhenExpression><![CDATA[the_condition]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[my_condition ? $V{PAGE_NUMBER} : ""]]></textFieldExpression>
</textField>

Jasper Report text new line when Chinese+number String overflow lose

I use traditional Chinese ,and set the Stretch with overflow.
I find the Jasper report lose some characters like above picture when it would create a new line.
my jrxml text :
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="352" y="0" width="140" height="30" isPrintWhenDetailOverflows="true" uuid="9855b06a-dfca-4a88-8830-efb1590c2d4e"/>
<box topPadding="1" leftPadding="4" bottomPadding="5" rightPadding="4">
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement verticalAlignment="Middle">
<font fontName="標楷體" pdfFontName="MHei-Medium" pdfEncoding="UniCNS-UCS2-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single" lineSpacingSize="1.1"/>
</textElement>
<textFieldExpression><![CDATA[$F{varyReason}]]></textFieldExpression>
</textField>
Do I lose some setting???

Merging the cells which have same data

I have a report which has the columns Type,S.No,Date.Here the Type column will have the same value for all rows.So i just want to merge all the cells of Type column.I have referred the below link
Group several same value field into a single cell
and tried with their suggestion.But if i do like that i am getting like in below image.
Edit:
Below is the code i am using in my jrxml for merging the cells which have same data.
<field name="type" class="java.lang.String"/>
<group name="type">
<groupExpression><![CDATA[$F{type}]]></groupExpression>
</group>
In detail band i tried by creating the fake statictext behind the type textfield like below.
<staticText>
<reportElement x="0" y="0" width="121" height="20"/>
<box>
<leftPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<text><![CDATA[]]></text>
</staticText>
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="121" height="20"/>
<box>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{type}]]></textFieldExpression>
</textField>
But no use.
Tried by using printWhenExpression in type textfield like below.
<textField>
<reportElement x="0" y="0" width="121" height="20">
<printWhenExpression><![CDATA[$V{type_COUNT} == 1]]></printWhenExpression>
</reportElement>
<box>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{type}]]></textFieldExpression>
</textField>
But no use.
If i add the bottom border for static text then the image looks like below.
Thank You.
Add the bottom border in GroupFooter band for group "type"

Avoid split of text field to multiple pages

I have a main report and in the main report a sub report called this:
<detail>
<band height="50">
<subreport>
<reportElement x="0" y="1" width="802" height="49" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
<subreportParameter name="project_id">
<subreportParameterExpression><![CDATA[$P{project_id}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["subs/Project_planned.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
There is a problem in the subreport because text fields in the detail band are split up on multiple pages what doesn't look very nice. Is there an option to prevent text fields from splitting up to multiple pages when using the property isStretchWithOverflow
Current code of a text field
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToBandHeight" x="555" y="0" width="99" height="21" isPrintInFirstWholeBand="true" forecolor="#000000"/>
<box leftPadding="2">
<topPen lineWidth="1.0" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineColor="#000000"/>
</box>
<textElement verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{logic}]]></textFieldExpression>
</textField>
Example on how it looks (sorry for the missing data):
Yes there is, but not on the text field. For the band the text field is in, you can set the Split Type to Prevent. if you set that on the Detail Band and the row needs to overflow to next page, it will move the entire row to the next page.

version compatibility issues with jasper reports and iReport

I have an existing jrxml files which is formatted like the code below:
<band height="25" isSplitAllowed="true">
<rectangle radius="0">
<reportElement key="rectangle-2" mode="Opaque" x="0" y="0" width="782" height="25" forecolor="#000000" backcolor="#EAECEF"/>
<graphicElement fill="Solid">
<pen lineWidth="0.5" lineStyle="Solid"/>
</graphicElement>
</rectangle>
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement key="textField-4" mode="Opaque" x="2" y="2" width="774" height="20" forecolor="#000000" backcolor="#EAECEF"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>....
<leftPen lineWidth=
When I edit the jrxml file using iReport 3.7.0 or 4.1.1 it will change the format of that xml to the something below:
<band height="25" splitType="Stretch">
<rectangle radius="0">
<reportElement key="rectangle-2" mode="Opaque" x="0" y="0" width="782" height="25" forecolor="#000000" backcolor="#EAECEF"/>
<graphicElement fill="Solid">
<pen lineWidth="0.5" lineStyle="Solid"/>
</graphicElement>
</rectangle>
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement key="textField-4" mode="Opaque" x="2" y="2" width="774" height="20" forecolor="#000000" backcolor="#EAECEF"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#FFFFFF"/>
</box>
How can I preserve the format of the jrxml file?