jasper-reports

Jaspersoft studio adjust position of fields relative to height of other fields


I am trying to create a report in Jaspersoft Studio 6.15. and I hit a wall that I can't seem to break.

The thing is I need to align my Static and Text fields depending on Stretch/NoStretch of the previous one.

In my report I want to add few text fields along with their (static text)labels aligned horizontally like

ID : $F{ID}

Name: $F{Name}

Address: $F{Address}

But I'm unable to align them. This is what I tried

Position Type: float (for all static text and fields)
Stretch Type: no stretch (for all static text and fields)
Stretch With Overflow: True (for all dynamic text fields)

The image shows what I get and what I want. Moreover, my text field's content is dynamic i.e. content size could vary.

This is what I get: [![This is what I get][1]][1]

This is what it should be: [![This is what it should be][2]][2]

I've read many forums but could not find a solution, please suggest.

Thanks

EDIT:

Now I am getting this:

[![Now I am getting this][3]][3]


Solution

  • Nest each static and text field pair into a frame element:

            <frame>
                <reportElement ... positionType="Float"/>
                <staticText>
                    ...
                </staticText>
                <textField isStretchWithOverflow="true">
                    ...
                </textField>
            </frame>
            <frame>
                ...
            </frame>
            ...
    

    If the elements are to be included in the detail section, you can also create a separate band for each pair:

    <detail>
        <band>
            <staticText>
                ...
            </staticText>
            <textField isStretchWithOverflow="true">
                ...
            </textField>
        </band>
        <band>
            ...
        </band>
        ...
    </detail>