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

How to adjust bands heights (stretch and "shrink") so report occupies whole page?


silvio.araujo

Recommended Posts

Hi guys!

I’m new in Jasper Reports, so my problem may be easy for you, but is hard to me! I have a more complex report, but I create a new one, almost-empty, to exemplify it. In this example, I have two bands, the page header band and the details band. Inside the details band I put a frame, with a border all-around it.

My page header band can stretch, depending on the growth of data inside it. I need that page header first grows as it needs, AND THAN detail band grows FOR THE REST OF THE PAGE.

I tried to let detail band lower than the space for A4 paper, but it will stretch only if data inside of it requires, but I need that it grows ALLWAYS… So, I tried to pull it manually, during design-time, but than the header band could not grow, because there’s no space to do it (detail band does not “shrink” back if space is not used)…

Someone have any idea? Here is my code:

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final using      JasperReports Library version 6.6.0  --><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="595" pageHeight="842" columnWidth="555"              leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"              uuid="159b06a6-4453-4af1-aadf-8f0c096d21e9">     <property name="com.jaspersoft.studio.data.defaultdataadapter"               value="One Empty Record"/>     <queryString><![CDATA[]]></queryString>     <background><band splitType="Stretch"/></background>     <pageHeader><band height="168" splitType="Stretch"/></pageHeader>     <detail>          <band height="188" splitType="Stretch">                <property name="com.jaspersoft.studio.layout"                          value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>                <frame>                     <reportElement positionType="Float" stretchType="RelativeToBandHeight"                                    x="0" y="0" width="555" height="188"                                    uuid="166cb97c-a43c-4a0d-8b73-692a1ccbc82f"/>                     <box>                          <topPen    lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>                          <leftPen   lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>                          <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>                          <rightPen  lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>                     </box>                </frame>          </band>     </detail></jasperReport>[/code]
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

I could not believe Jasper Reports could not do such a common thing! There must be some alternatives... Perhaps some event control that I could capture the control during report generation and adjust detail band height of last report page, according with used space or height of page header band...

Link to comment
Share on other sites

Just take a look at my sample, I guess you want to achieve, that there is a border around all your details. Neithertheless what height the dynamic page header will consume and also if there is just one little detail, the border should run to the bottom of the page, correct?!?

So therefore you can use a SubReport with flag "RunToBottom = true" and place a frame around your SubReport with the border set.

Here is the MasterReport:

 

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.5.1  --><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="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="159b06a6-4453-4af1-aadf-8f0c096d21e9">    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>    <queryString>        <![CDATA[]]>    </queryString>    <background>        <band splitType="Stretch"/>    </background>    <pageHeader>        <band height="168" splitType="Stretch">            <staticText>                <reportElement x="94" y="35" width="356" height="30" uuid="93e91889-5ffd-4621-9a7b-cef30e5402ec"/>                <text><![CDATA[Page Header Text from MasterReport 1]]></text>            </staticText>        </band>    </pageHeader>    <detail>        <band height="100" splitType="Stretch">            <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>            <frame>                <reportElement x="0" y="0" width="555" height="100" uuid="ea8cda4a-819c-41fd-8261-119973f32961"/>                <box>                    <pen lineWidth="1.0"/>                </box>                <subreport isUsingCache="true" runToBottom="true">                    <reportElement mode="Opaque" x="0" y="0" width="555" height="100" backcolor="#BAD1F5" uuid="ad667086-8d2c-4d4c-8b9e-94dfad4e79a6"/>                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(2)]]></dataSourceExpression>                    <subreportExpression><![CDATA["stretchBands_SubReport.jasper"]]></subreportExpression>                </subreport>            </frame>        </band>    </detail></jasperReport>[/code]

And this is just the SubReport for Rendering the detail records:

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.5.1  --><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="stretchBands_SubReport" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="e56c0ca2-457d-440f-9574-41df1e8c536b">    <property name="com.jaspersoft.studio.unit." value="pixel"/>    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>    <queryString>        <![CDATA[]]>    </queryString>    <detail>        <band height="125" splitType="Stretch">            <staticText>                <reportElement x="20" y="20" width="332" height="30" uuid="2bc68575-f3b6-4e4d-898b-1145e51d17a6"/>                <text><![CDATA[static Text for Detail in SubReport]]></text>            </staticText>            <textField>                <reportElement x="20" y="50" width="332" height="30" uuid="6684cf42-9d1e-40d7-a04a-5dfc887787b2"/>                <textFieldExpression><![CDATA["SubReport RecordNumber: " +$V{REPORT_COUNT}]]></textFieldExpression>            </textField>        </band>    </detail></jasperReport>[/code]

hth + regards from Dresden/Germany

C-Box

Link to comment
Share on other sites

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