Jump to content
Changes to the Jaspersoft community edition download ×

Need help with multiple line text field alignment


jzhao

Recommended Posts

Hi, I have a problem to align multiple fields if some of them have contents overflowing. eg.

 

row1: field1 field3 field5

row2: field2 filed4 field6

 

These fields are popped from database with many records. some of them may have long contents that will possible overflow some fields, say, field1. So I set all the fields with "stretch with overflow" and stretch type = relativeToBandHeight or relativeToTollestObject. The results are not accecptable. Since row2 is not aligned with row1 well if row 1 overflowed(either overlaying or leaving space between). I also tried to set the Position Type to float. Not get good results. Please help!!

Thanks

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

You only need to set isStretchWithOverflow for all text fields and positionType="Float" for the ones on the second row. Do not set any stretchType attribute.

 

Also make sure that the elements on the second row start below the one on the first row (if they overlap with as few as 1 pixel, positionType="Float" would not work).

 

HTH,

Lucian

Link to comment
Share on other sites

Hi, Lucianc,

 

Thanks a lot. It worked only if the second row without overflowing field, and the first row need to have stretchType set(otherwise only the field with overflowing content extended, other fields in this same row will not expended).

 

The problem is:

If second row also has field overflowing, say field2 in my first post, no matter how the stretchType set or not set, the contents in the overflowing field will not be shown(other fields in this same row will be shown).

 

I also tried some other reports, the problem is general like this: in a report, if a second row/third row/... has mutiple fields and the positionType is set as float, and some of the fields have overflowing contents, then that field will not extend.

 

Would you please give me idea?

 

Thanks again.

 

jzhao

 

 

lucianc wrote:

You only need to set isStretchWithOverflow for all text fields and positionType="Float" for the ones on the second row. Do not set any stretchType attribute.

Also make sure that the elements on the second row start below the one on the first row (if they overlap with as few as 1 pixel, positionType="Float" would not work).


HTH,
Lucian
Link to comment
Share on other sites

  • 2 weeks later...

Thank you a lot, and please forgive me not here for a while since I was assigned to other projects.

 

The jrxml code looks like this:

 

================================

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport

name="test"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

pageWidth="595"

pageHeight="842"

columnWidth="535"

columnSpacing="0"

leftMargin="30"

rightMargin="30"

topMargin="20"

bottomMargin="20"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

<property name="ireport.scriptlethandling" value="0" />

<property name="ireport.encoding" value="UTF-8" />

<import value="java.util.*" />

<import value="net.sf.jasperreports.engine.*" />

<import value="net.sf.jasperreports.engine.data.*" />

 

<field name="ADDRESS_LINE_1" class="java.lang.String"/>

<field name="ADDRESS_LINE_2" class="java.lang.String"/>

<field name="CITY" class="java.lang.String"/>

<field name="PROVINCE" class="java.lang.String"/>

<field name="COUNTRY" class="java.lang.String"/>

<field name="POSTAL" class="java.lang.String"/>

 

<background>

<band height="0" isSplitAllowed="true" >

</band>

</background>

<title>

<band height="32" isSplitAllowed="true" >

<staticText>

<reportElement

x="0"

y="9"

width="95"

height="23"

key="staticText-1"/>

<box topBorder="1Point" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font/>

</textElement>

<text><![CDATA[address]]></text>

</staticText>

<staticText>

<reportElement

x="94"

y="9"

width="161"

height="23"

key="staticText-2"/>

<box topBorder="1Point" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font/>

</textElement>

<text><![CDATA[city]]></text>

</staticText>

<staticText>

<reportElement

x="255"

y="9"

width="93"

height="23"

key="staticText-3"/>

<box topBorder="1Point" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font/>

</textElement>

<text><![CDATA[province]]></text>

</staticText>

<staticText>

<reportElement

x="348"

y="9"

width="93"

height="23"

key="staticText-4"/>

<box topBorder="1Point" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font/>

</textElement>

<text><![CDATA[postal]]></text>

</staticText>

<staticText>

<reportElement

x="441"

y="9"

width="93"

height="23"

key="staticText-5"/>

<box topBorder="1Point" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font/>

</textElement>

<text><![CDATA[country]]></text>

</staticText>

<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="252"

y="1"

width="282"

height="10"

forecolor="#000000"

key="textField-7"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement textAlignment="Right" verticalAlignment="Middle">

<font fontName="Courier New" size="7"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$V{PAGE_NUMBER} + " "]]></textFieldExpression>

</textField>

</band>

</title>

<pageHeader>

<band height="10" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="1"

y="0"

width="534"

height="10"

forecolor="#000000"

key="textField-6"

isRemoveLineWhenBlank="true">

<printWhenExpression><![CDATA[new Boolean(

$V{PAGE_NUMBER}.intValue() !=1

)]]></printWhenExpression>

</reportElement>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="1Point" bottomBorderColor="#000000"/>

<textElement textAlignment="Right" verticalAlignment="Middle">

<font fontName="Courier New" size="7"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$V{PAGE_NUMBER} + " "]]></textFieldExpression>

</textField>

</band>

</pageHeader>

<columnHeader>

<band height="0" isSplitAllowed="true" >

</band>

</columnHeader>

<detail>

<band height="22" isSplitAllowed="true" >

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="94"

y="0"

width="161"

height="12"

key="textField-2"

stretchType="RelativeToTallestObject"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{CITY}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="255"

y="0"

width="93"

height="12"

key="textField-3"

stretchType="RelativeToTallestObject"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{PROVINCE}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="348"

y="0"

width="93"

height="12"

key="textField-4"

stretchType="RelativeToTallestObject"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{POSTAL}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="441"

y="0"

width="93"

height="12"

key="textField-5"

stretchType="RelativeToTallestObject"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{COUNTRY}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="0"

y="0"

width="95"

height="12"

key="textField-9"

stretchType="RelativeToTallestObject"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{ADDRESS_LINE_1}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="0"

y="10"

width="95"

height="12"

key="textField-10"

positionType="Float"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{ADDRESS_LINE_2}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="94"

y="12"

width="161"

height="10"

key="textField-11"

positionType="Float"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA["111"]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="255"

y="12"

width="93"

height="10"

key="textField-12"

positionType="Float"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA["222"]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="348"

y="12"

width="93"

height="10"

key="textField-13"

positionType="Float"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA["333"]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="441"

y="12"

width="93"

height="10"

key="textField-14"

positionType="Float"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>

<textElement>

<font size="8" pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA["444"]]></textFieldExpression>

</textField>

</band>

</detail>

<columnFooter>

<band height="0" isSplitAllowed="true" >

</band>

</columnFooter>

<pageFooter>

<band height="0" isSplitAllowed="true" >

</band>

</pageFooter>

<summary>

<band height="0" isSplitAllowed="true" >

</band>

</summary>

</jasperReport>

Post edited by: jzhao, at: 2006/11/17 23:11

Link to comment
Share on other sites

You have a very funny understanding of the meaning of simple.

 

Regarding your report:

  • Don't set stretchType="RelativeToTallestObject" for any element.

The elements in the second row need to be placed bellow the elements in the first row. In your case, you have y=0, height=12 in the first row and y=10 in the second row.[/ul]

 

HTH,

Lucian

Link to comment
Share on other sites

Thanks,

 

But there is still problem. If Don't set stretchType="RelativeToTallestObject" for any element, there are different height in a row. That is not acceptable in a report presented as a table.

 

Hope there is a way to solve this problem.

 

John

 

lucianc wrote:

You have a very funny understanding of the meaning of simple.

Regarding your report:
  • Don't set stretchType="RelativeToTallestObject" for any element.
  • The elements in the second row need to be placed bellow the elements in the first row. In your case, you have y=0, height=12 in the first row and y=10 in the second row.[/ul]

    HTH,
    Lucian
Link to comment
Share on other sites

Setting stretchType="RelativeToTallestObject" for an element that could push down elements bellow it is not a good idea, since the elements bellow could get pushed out of the band.

 

There are several workarounds for this if you want a details band consisting of two stretchable rows:

  • Nest all the elements in a row in a <frame> element and set stretchType="RelativeToBandHeight" for all the elements in the frame. The frame corresponding to the second row should have positionType="Float".

Use a dummy group to break the detail band into several bands, obtaining a band for each detail row. All the elements in a band/row would then have stretchType="RelativeToBandHeight".

etc[/ul]

 

HTH,

Lucian

Link to comment
Share on other sites

  • 2 weeks later...

Hi, Lucian,

 

I have tested in my application. It works very well only if the first row is not overflowing the frame/dummy group band. If both rows have fields overflowing the bands, the second rows will be lost.

 

Actually, I have 12 row repeated data from database that need to put on a table report in three columns. Do not know in advance which row will have overflowing data.

 

Of course if I set all the bands large enough to host the contains of the database fields, it will have no problem. but it looks lousy.

 

Thank you very much,

 

JZhao

 

Post edited by: jzhao, at: 2006/12/05 06:03

Post edited by: jzhao, at: 2006/12/05 06:14

Link to comment
Share on other sites

  • 10 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...