How to have a column name spanning multiple rows in jasper generation

I wrote a jasper specification for generating PDF from a table data source. This is working fine. Now I need to add a few more columns, and the report now does not look very good. Now I think, can I compress the column names in several rows, for example below

Date of service

to

Maintenance

the date

Can this be achieved in Jasper?

Regards, Paul

+5
source share
2 answers

Are your column names hardcoded? You just need to change the "Service Date" to "Service \ nDate" to return the carriage?

. "\n" " ". . , Static Text iReport .

, . , .

+3

JasperReports API, :

    //Detail
    band = new JRDesignBand();
    band.setHeight(40);

    JRDesignStaticText staticText = new JRDesignStaticText();
    staticText.setX(0);
    staticText.setY(0);
    staticText.setWidth(60);
    staticText.setHeight(20);
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    staticText.setStyle(boldStyle);
    staticText.setText("ID: ");
    staticText.getLineBox().getLeftPen().setLineWidth(1);
    staticText.getLineBox().getTopPen().setLineWidth(1);
    staticText.getLineBox().setLeftPadding(10);
    band.addElement(staticText);

    textField = new JRDesignTextField();
    textField.setX(60);
    textField.setY(0);
    textField.setWidth(200);
    textField.setHeight(20);
    textField.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.Integer.class);
    expression.setText("$F{Id}");
    textField.setExpression(expression);
    textField.getLineBox().getTopPen().setLineWidth(1);
    textField.getLineBox().getRightPen().setLineWidth(1);
    textField.getLineBox().setLeftPadding(10);
    band.addElement(textField);

    staticText = new JRDesignStaticText();
    staticText.setX(0);
    staticText.setY(20);
    staticText.setWidth(60);
    staticText.setHeight(20);
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    staticText.setStyle(boldStyle);
    staticText.setText("Name: ");
    staticText.getLineBox().getLeftPen().setLineWidth(1);
    staticText.getLineBox().getBottomPen().setLineWidth(1);
    staticText.getLineBox().setLeftPadding(10);
    band.addElement(staticText);


    textField = new JRDesignTextField();
    textField.setStretchWithOverflow(true);
    textField.setX(60);
    textField.setY(20);
    textField.setWidth(200);
    textField.setHeight(20);
    textField.setPositionType(PositionTypeEnum.FLOAT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{FirstName} + \" \" + $F{LastName}");
    textField.setExpression(expression);
    textField.getLineBox().getRightPen().setLineWidth(1);
    textField.getLineBox().getBottomPen().setLineWidth(1);
    textField.getLineBox().setLeftPadding(10);
    band.addElement(textField);

    ((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);

:

enter image description here

jrxml:

<detail>
    <band height="40" splitType="Stretch">
        <staticText>
            <reportElement x="0" y="0" width="60" height="20"/>
            <box leftPadding="10">
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[ID: ]]></text>
        </staticText>
        <textField>
            <reportElement x="60" y="0" width="200" height="20"/>
            <box leftPadding="10">
                <topPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{Id}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement x="0" y="20" width="60" height="20"/>
            <box leftPadding="10">
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[Name: ]]></text>
        </staticText>
        <textField>
            <reportElement x="60" y="20" width="200" height="20"/>
            <box leftPadding="10">
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{FirstName} + " " + $F{LastName}]]></textFieldExpression>
        </textField>
    </band>
</detail>
+1

All Articles