Jump to content
We've recently updated our Privacy Statement, available here ×

How to adjust text field with stretch with overflow


blessed_spot

Recommended Posts

I use ireport 4.5.1 (I know it's so so old but it's at work and I don't have authority to upgrade it). 
Anyway, I have a text field with following value:

    $F{field1} + " — " + $F{field2}
Both field1 and field 2 are of java.lang.string type.
Since neither field1 nor field2 has consistent length, I have checked the stretch with the overflow property as TRUE. But the problem is that when I have a long text for field2 the rest of it comes below field1 while I need it begin right below field2.

Actually, it appears like: 

    something for field1 — something very long 
    for field2

While I need it like:

    something for field1 — something very long 
                           for field2
and if I put  $F{field1} in a separate text field, since it doesn't have a fixed length, sometimes an extra space appears after $F{field1} or if I set its stretch with overflow property as TRUE, $F{field1} appears in two lines, which I don't like it either.
Generally, I need $F{field1} appear in one line with only one space after that and $F{field2} to split in two lines, if its length is too long, and appear as I described above.
Is there any way to do that?

Here's jrxml file: 

    <?xml version="1.0" encoding="UTF-8"?>
    <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="adjust_textField" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <parameter name="parameter1" class="java.lang.Integer"/>
        <queryString>
            <![CDATA[sELECT id, code, name FROM test_co1
    WHERE id = $P{parameter1}]]>
        </queryString>
        <field name="id" class="java.lang.Integer"/>
        <field name="code" class="java.lang.String"/>
        <field name="name" class="java.lang.String"/>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band splitType="Stretch"/>
        </title>
        <pageHeader>
            <band splitType="Stretch"/>
        </pageHeader>
        <columnHeader>
            <band splitType="Stretch"/>
        </columnHeader>
        <detail>
            <band height="125" splitType="Stretch">
                <textField isStretchWithOverflow="true">
                    <reportElement positionType="Float" x="41" y="66" width="270" height="20"/>
                    <textElement verticalAlignment="Bottom">
                        <font fontName="Gill Sans MT" size="12" isBold="true"/>
                    </textElement>
                    <textFieldExpression class="java.lang.String"><![CDATA[$F{code} + " — " + $F{name}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
        <columnFooter>
            <band splitType="Stretch"/>
        </columnFooter>
        <pageFooter>
            <band splitType="Stretch"/>
        </pageFooter>
        <summary>
            <band splitType="Stretch"/>
        </summary>
    </jasperReport>

Which reads data from the following table: 

    CREATE TABLE public.test_co1 (
      id INTEGER,
      code TEXT,
      name TEXT
    ) ;
    
    /* Data for the 'public.test_co1' table  (Records 1 - 54) */
    
    INSERT INTO public.test_co1 ("id", "code", "name")
    VALUES 
      (1, E'J', E'WELDING & CUTTING'),
      (2, E'L', E'CONFINED SPACES'),
      (6, E'N', E'COMPRESSED GAS/FUEL CYLINDERS'),
      (7, E'K', E'NOISE EXPOSURE'),
      (8, E'I', E'RESPIRATORY PROTECTION'),
      (10, E'H', E'BLOODBORNE PATHOGENS'),
      (13, E'M', E'LOCKOUT/TAGOUT'),
      (30, E'L2', E'EXCAVATION AND TRENCHING'),
      (31, E'MISC3.5', E'Miscellaneous Class 3.5 Hours'),
      (32, E'MISC3', E'Miscellaneous Class 3 Hours'),
      (34, E'VIP80', E'LOCAL 80 TRAINING DOCUMENTS'),
      (38, E'DGPTP', E'DIRECTORS GUILD - PRODUCER TRAINING PROGRAM'),
      (39, E'MISC4.0', E'Miscellaneous Class 4.5 Hours'),
      (44, E'HOS', E'HOURS OF SERVICE'),
      (50, E'B1b1b1', E'CONDOR AERIAL LIFT'),
      (51, E'BCb1b1', E'Cribbing'),
      (52, E'B2b1b1', E'SPECIAL AERIAL LIFT FOR SET LIGHTING TECHNICIANS'),
      (53, E'B3b1b1', E'SPECIAL AERIAL LIFT FOR STUDIO GRIPS'),
      (3, E'O', E'he target table is joined to the tables mentioned '),
      (12, E'C1', E'he target table is joined to the tables mentioned '),
      (41, E'O1', E'he target table is joined to the tables mentioned '),
      (9, E'82018', E'less'),
      (40, E'82018', E'less'),
      (46, E'82018', E'less'),
      (11, E'D', E'row'),
      (22, E'D1', E'row'),
      (4, E'W18', E'MAKE-UP ARTISTS FACIAL APPL.'),
      (19, E'W18', E'ROPE & KNOT RIGGING'),
      (20, E'W18', E'INTERMEDIATE WEAPONS'),
      (24, E'W18', E'GREENBED ASSEMBLY'),
      (25, E'W18', E'CAR MOUNTS FOR GRIPS'),
      (26, E'W18', E'HIGH ANGLE RESCUE'),
      (27, E'W18', E'LOCAL 600 GENERAL RESPR. PROT.'),
      (28, E'W18', E'GRIPS 32 RIGGING COURSE'),
      (18, E'W18', E' 6 numbers. some have less than 6 numbers. '),
      (23, E'W18', E'less'),
      (16, E'W18', E'than'),
      (42, E'HP2', E'java code to iReport 5.5.0rnstm.saurabh94  (2) 7 hours 53 min ago iReport Designer'),
      (48, E'HP1', E'java code to iReport 5.5.0rnstm.saurabh94  (2) 7 hours 53 min ago iReport Designer'),
      (37, E'GD$', E'ASSISTANT DIRECTOR TRAINING PROGRAM - NEW YORK'),
      (17, E'W18', E'java code to iReport 5.5.0'),
      (21, E'W18', E'java code to iReport'),
      (29, E'S', E'java code to iReportFIREARM SAFETY'),
      (33, E'E2', E'java code to iReportFIRE EXTINGUISHER SAFETY'),
      (35, E'R', E'java code to iReportRIGGING SAFETY'),
      (36, E'V', E'java code to iReportLIGHTING SAFETY'),
      (43, E'r1', E'java code to iReportRIGGING SAFETY'),
      (47, E'V2', E'java code to iReportWORKPLACE ELECTRICIAL SAFETY'),
      (54, E'B5b1b1', E'java code to iReportTRADITIONAL INSERT CAR SAFETY'),
      (5, E'W18', E'java code to iReportLOCATION SAFETY'),
      (14, E'W18', E'java code to iReportBASIC FIREARM SAFETY CERT.'),
      (15, E'W18', E'java code to iReportWEAPON SAFETY FOR PROP. MASTERS'),
      (45, E'GD$', E'java code to iReportGENERAL SAFETY TRAINING/INJURY & ILLNESS PREVENTION PROGRAM'),
      (49, E'GD$', E'java code to iReportENVIRONMENTAL SAFETY');

When you enter 45 as the parameter value, it displays it as 

    GD$ — java code to iReportGENERAL SAFETY
    TRAINING/INJURY & ILLNESS PREVENTION
    PROGRAM


while I need it as :

    GD$ — java code to iReportGENERAL SAFETY
          TRAINING/INJURY & ILLNESS PREVENTION
          PROGRAM

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...