How to make all boxes from text field share the same border height - IReports, JasperReport - jasper-reports

Im making a report using JasperReports and iReport, and since im not using a table, what i'm doing now to give it some sort of table like border, is giving the left and right border of each textfield a dotted style.
But, i won't always have the same data in each box, and this is causing the borders to be of different height.
I also would like for the borders to meet each other, but no matter what i change or move, there's always a space in between each box.
But for now, the most important thing is for each box to have the same height.
This is a picture of my report:
This is what each box looks like, they're all similar so i just pasted one the xml of one box:
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement key="textField-1" mode="Transparent" x="7" y="0" width="177" height="0" isRemoveLineWhenBlank="true" forecolor="#000000" backcolor="#FFFFFF">
<printWhenExpression><![CDATA[$F{RESULTMICRO1}!=null]]></printWhenExpression>
</reportElement>
<box leftPadding="1">
<pen lineWidth="0.0"/>
<topPen lineWidth="0.5" lineStyle="Dashed"/>
<leftPen lineWidth="0.5" lineStyle="Dashed"/>
<bottomPen lineWidth="0.5" lineStyle="Dashed"/>
<rightPen lineWidth="0.5" lineStyle="Dashed"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Top" rotation="None">
<font fontName="Courier New" size="9" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Courier-Bold" pdfEncoding="Cp1252" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{RESULTMICRO1}]]></textFieldExpression>
If anyone could help me, i'd appreciate it.

Related

JasperReports: paddings misbehave in table body cells

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?

Hiding the field in jasper report

I am working with jasper report-4.5.0.I want to hide a field in jasper based on the flag value.Below is tha code which i am using in columnHeader band.
<staticText>
<reportElement x="365" y="0" width="100" height="20"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[TotalCharge]]></text>
</staticText>
and below code i am using in detail band.
<textField>
<reportElement x="365" y="0" width="100" height="20">
<printWhenExpression><![CDATA[!$P{dataType}]]></printWhenExpression>
</reportElement>
<box>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{chargeTotal}]]></textFieldExpression>
</textField>
i am declaring the parameter in jrxml as
<parameter name="dataType" class="java.lang.Boolean"/>
the value to this parameter is coming from java class.If it is the false value i dont want to display this chargeTotal column.What i am doing wrong in my code.I am not getting.Any one can point me where i am doing wrong its urgent to me.
The code snippets you provided for the textfield look correct, but if you are wanting to hide the column header also you need to also add a printWhenExpression for it.
<staticText>
<reportElement x="365" y="0" width="100" height="20">
<printWhenExpression><![CDATA[$P{dataType}]]></printWhenExpression>
</reportElement>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[TotalCharge]]></text>
</staticText>
Edit: Actually, you have the conditional value backwards. If you want to show the column when dataType is true, your printWhenExpression needs to look like:
<printWhenExpression><![CDATA[$P{dataType}]]></printWhenExpression>

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.

Centering data in crosstab column

This picture shows a sample of what my columns look like in my crosstab (I have two column groups - in this case a date and status). The date should be centered across the 5 columns and I have set the horizontal to be centered. However, it's only centering it based on the size I have set in iReport. I've tried adjusting the various settings but have been unable to center that first row. I'm using JasperReports 4.0.1.
I know it's a little late, but this is how yo do it:
when you declare the columnGroup element, set the headerPosition attribute to "Stretch". Example:
<columnGroup name="month" height="20" headerPosition="Stretch">
<bucket>
<bucketExpression class="java.lang.String"><![CDATA[$F{month}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents backcolor="#999999" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="16" height="20"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression class="java.lang.String"><![CDATA[$V{month}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents/>
</crosstabTotalColumnHeader>
Regards,
Damian

vertical text alignment in jasper reports

I have a table in a jasper report, and I need the contents of certain cells in that table to be vertically aligned. I'm attempting to edit the report with iReport.
In iReport I can go into the properties of a cell and see that the vertical align is set to "Middle". Additionally, when I look at the XML directly (see below), I can see that the textElement tag has a verticalAlignment="Middle" attribute.
So near as I can tell the text should be vertically aligned within its little box, and yet it will not align properly.
I'm hoping that someone experienced with vertically aligning things in jasper reports can point out what I'm doing wrong. Thanks much.
<textField
isStretchWithOverflow="false"
isBlankWhenNull="true"
evaluationTime="Now"
hyperlinkType="None"
hyperlinkTarget="Self" >
<reportElement
x="227"
y="0"
width="31"
height="14"
key="textField-4"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" pdfFontName="Times-Roman" size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{someVariableName}]]></textFieldExpression>
</textField>
So, to be clear, what I have in my report is something like this:
|--------|
| text |
| |
| |
|--------|
And what I want is something like this:
|--------|
| |
| text |
| |
|--------|
Here's how I fixed this problem (iReport 3.7.6):
In Designer tab:
Right Click on the Static Text Box
Select "Padding and Borders"
In the pop up box, Increase the "Top" or "Bottom" value by, for example, 5, and click OK to see the result of this change.
As you can see, this will allow you to position your Static Text exactly how you want.
If you can only make the change in the XML, this is how the change showed up in XML:
<box topPadding="4"/>
Example w/ the Static Text code block:
<staticText>
<reportElement positionType="Float" mode="Opaque" x="14" y="27" width="118" height="14" forecolor="#FFFFFF" backcolor="#909090"/>
<box topPadding="4"/>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single" markup="none">
<font fontName="Arial" size="7" isBold="true" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false"/>
</textElement>
<text><![CDATA[SAMPLE TEXT SAMPLE TEXT]]></text>
</staticText>
you can 1) check if positionType="FixRelativeToTop" 2) create a style with alingn = middle and apply it to your item - maybe this can help.