Increase / Decrease band height appropriately with overflowing text

0

Report output speaks of the issue, Any help or advice here is highly appreciated. Code inculuded below.

The second band resizes appropriately when text is more - so height is max of text and image frame. But when text is little as in first band scenario, need the band to size to max height of text and image frame. 

 

<?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="Test" pageWidth="600" pageHeight="800" whenNoDataType="AllSectionsNoDetail" columnWidth="520" leftMargin="40" rightMargin="40" topMargin="0" bottomMargin="0">
<queryString>
  <![CDATA[SELECT 'Test Report' as Report FROM DUAL]]>
</queryString>
<detail>
  <band height="20">
   <line>
    <reportElement x="0" y="19" width="540" height="1"/>
   </line>
  </band>
  <band height="100">
   <textField isStretchWithOverflow="true">
    <reportElement x="0" y="0" width="150" height="0" isRemoveLineWhenBlank="true"/>
    <box>
     <pen lineWidth="0.1" lineColor="#00FF00"/>
    </box>
    <textFieldExpression><![CDATA["This is some long text. This is some long text. "+
      "This is some long text. This is some long text. "]]></textFieldExpression>
   </textField>
   <frame>
    <reportElement positionType="Float" x="0" y="0" width="150" height="100" isRemoveLineWhenBlank="true">
     <printWhenExpression><![CDATA[false]]></printWhenExpression>
    </reportElement>
   </frame>
   <frame>
    <reportElement x="200" y="0" width="300" height="100" isRemoveLineWhenBlank="true"/>
    <box>
     <pen lineWidth="0.1" lineColor="#0000FF"/>
    </box>
    <!-- One of the below frames is always printed and the other not -->
    <frame>
     <reportElement x="0" y="0" width="300" height="50" isRemoveLineWhenBlank="true">
      <printWhenExpression><![CDATA[false]]></printWhenExpression>
     </reportElement>
     <staticText>
      <reportElement x="50" y="15" width="200" height="30"/>
      <text><![CDATA[This frame height has to be fixed, to fit some fixed size images in here.]]></text>
     </staticText>
    </frame>
    <frame>
     <reportElement x="0" y="50" width="300" height="50" isRemoveLineWhenBlank="true">
      <printWhenExpression><![CDATA[true]]></printWhenExpression>
     </reportElement>
     <staticText>
      <reportElement x="50" y="15" width="200" height="30"/>
      <text><![CDATA[This frame height has to be fixed, to fit some fixed size images in here.]]></text>
     </staticText>
    </frame>
   </frame>
  </band>
  <band height="20">
   <line>
    <reportElement x="0" y="0" width="540" height="1"/>
   </line>
   <line>
    <reportElement x="0" y="19" width="540" height="1"/>
   </line>
  </band>
  <band height="100">
   <textField isStretchWithOverflow="true">
    <reportElement x="0" y="0" width="150" height="0" isRemoveLineWhenBlank="true"/>
    <box>
     <pen lineWidth="0.1" lineColor="#00FF00"/>
    </box>
    <textFieldExpression><![CDATA["This is some long text. This is some long text. "+
      "This is some long text. This is some long text. "+
      "This is some long text. This is some long text. "]]></textFieldExpression>
   </textField>
   <frame>
    <reportElement positionType="Float" x="0" y="0" width="150" height="100" isRemoveLineWhenBlank="true">
     <printWhenExpression><![CDATA[false]]></printWhenExpression>
    </reportElement>
   </frame>
   <frame>
    <reportElement x="200" y="0" width="300" height="100" isRemoveLineWhenBlank="true"/>
    <box>
     <pen lineWidth="0.1" lineColor="#0000FF"/>
    </box>
    <!-- One of the below frames is always printed and the other not -->
    <frame>
     <reportElement x="0" y="0" width="300" height="50" isRemoveLineWhenBlank="true">
      <printWhenExpression><![CDATA[false]]></printWhenExpression>
     </reportElement>
     <staticText>
      <reportElement x="50" y="15" width="200" height="30"/>
      <text><![CDATA[This frame height has to be fixed, to fit some fixed size images in here.]]></text>
     </staticText>
    </frame>
    <frame>
     <reportElement x="0" y="50" width="300" height="50" isRemoveLineWhenBlank="true">
      <printWhenExpression><![CDATA[true]]></printWhenExpression>
     </reportElement>
     <staticText>
      <reportElement x="50" y="15" width="200" height="30"/>
      <text><![CDATA[This frame height has to be fixed, to fit some fixed size images in here.]]></text>
     </staticText>
    </frame>
   </frame>
  </band>
  <band height="1">
   <line>
    <reportElement x="0" y="0" width="540" height="1"/>
   </line>
  </band>
</detail>
</jasperReport>

bijju's picture
3
Joined: Dec 26 2014 - 1:20pm
Last seen: 4 years 9 months ago

2 Answers:

0

The problem you are experiencing is that the Detail band is growing by the same amount as the textfield. if you allocate the text field the same amount of space as the frame then the band will expand by the correct amount:

 

 

allen.cox's picture
Joined: Sep 12 2013 - 6:23am
Last seen: 11 months 4 days ago

<reportElement x="0" y="0" width="150" height="100"/>

allen.cox - 4 years 9 months ago

But that keeps the height of the band fixed (the text field would take entire height even when it has few chars). I had it that way, so band would shrink according to the content

bijju - 4 years 9 months ago

After some edit to the code, when there is large text(2nd band) the band height is keeping to the max height of either frames, which is expected. But if text is small(1st band) - I still need the band height ta be max height - so it should just fit upto the image frame on the right, with no extra space below.

bijju - 4 years 9 months ago
1

Hi,

I think here we have two columns that need to collapse independent of one another.

The only solution that I can see right now is to isolate the content of those two columns that run side by side in two separate subreports.

This is because only subreports allow you to have content bigger than the subreport element height itself.

We are working on a modification of layout code to allow frame elements to be smaller than their declared content height.

The frame would stretch to display all its content, even if the initial frame height declared at design time is smaller.

It would allow you to isolate the two columns in two separate frames, side by side, instead of having to use subreports.

Thanks,

Teodor

 

 

teodord's picture
4381
Joined: Jun 30 2006 - 9:00am
Last seen: 2 weeks 11 hours ago

As you only have 2 variations of the output you could adapt what you already have.

Create 2 detail bands, one with the smaller frame height and one with the larger. Set the left field to be the same height as the frame in each case so that the expansion works correctly. Then use the print when expression on the band instead of the frame

allen.cox - 4 years 9 months ago

<?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="Test" pageWidth="600" pageHeight="800" whenNoDataType="AllSectionsNoDetail" columnWidth="520" leftMargin="40" rightMargin="40" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT 'Test Report' as Report FROM DUAL]]>
</queryString>
<detail>
<band height="20">
<line>
<reportElement x="0" y="19" width="540" height="1"/>
</line>
</band>
<band height="50">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="150" height="50" isRemoveLineWhenBlank="true"/>
<box>
<pen lineWidth="0.1" lineColor="#00FF00"/>
</box>
<textElement/>
<textFieldExpression><![CDATA["This is some long text. This is some long text. "+
"This is "]]></textFieldExpression>
</textField>
<frame>
<reportElement x="200" y="0" width="300" height="50" isRemoveLineWhenBlank="true"/>
<box>
<pen lineWidth="0.1" lineColor="#0000FF"/>
</box>
<staticText>
<reportElement x="50" y="11" width="200" height="30"/>
<textElement/>
<text><![CDATA[This frame height has to be fixed, to fit some fixed size images in here. 2]]></text>
</staticText>
</frame>
</band>
<band height="20">
<line>
<reportElement x="0" y="0" width="540" height="1"/>
</line>
<line>
<reportElement x="0" y="19" width="540" height="1"/>
</line>
</band>
<band height="75">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="150" height="75" isRemoveLineWhenBlank="true"/>
<box>
<pen lineWidth="0.1" lineColor="#00FF00"/>
</box>
<textElement/>
<textFieldExpression><![CDATA["This is some long text. This is some long text. "+
"This is some long text. This is some long text. "+
"This is some long text. This is some long text. "+
"This is some long text. This is some long text. "+
"This is some long text. This is some long text. "+
"This is some long text. This is some long text. "+

"This is some long text. This is some long text. "]]></textFieldExpression>
</textField>
<frame>
<reportElement x="200" y="0" width="300" height="75" isRemoveLineWhenBlank="true"/>
<box>
<pen lineWidth="0.1" lineColor="#0000FF"/>
</box>
<staticText>
<reportElement x="50" y="21" width="200" height="30"/>
<textElement/>
<text><![CDATA[This frame height has to be fixed, to fit some fixed size images in here. 3]]></text>
</staticText>
</frame>
</band>
<band height="1">
<line>
<reportElement x="0" y="0" width="540" height="1"/>
</line>
</band>
</detail>
</jasperReport>

allen.cox - 4 years 9 months ago

Allen, That works if that is the only data i am dealing (if only those mentioned two variations). But it has more to the problem(the image frame is kind of a vertical stack of images of which i will show a few and hide rest) and i tried to show the problem extracting a small piece of it. Thanks for the advice.

bijju - 4 years 9 months ago
show 1 more...

Teodor - I tried doing what you said, extracting the right frame into a sub report and setting the height of the sub-report as '0' in the main-report. That worked like a charm and is exactly what i am looking at. Thanks so much.

bijju - 4 years 9 months ago
Feedback
randomness