2016-03-03 110 views
1

我遇到了使用Jasper報告的問題。如何調整stetched textField底部的textField?

在我的報告中我試圖像對齊文本字段:

${name}      ${field1} 
${age}      ${field2} 
${address}     ${field3} 

文本字段${name}能夠stretchWithOverflow使其斷絕與${field1}對齊。

如果文本框${name}綿延我希望得到的結果,其中${field1}與上${name}最後一行被拉伸至對齊。

${name}      
${name}(stretched)   ${field1} 
${age}      ${field2} 
${address}     ${field3} 

我讀過很多論壇,但找不到解決方案。

+0

您好我張貼解答和編輯的問題(標題問題和一些小的語法)......也許你應該考慮在冠軍水平改變垂直或底部(標題似乎很奇怪......),但不能編輯,因爲我不想在沒有諮詢你的情況下改變你的原文(這篇文章是你的:) –

+0

嗨,謝謝你的回答!標題確實很奇怪,我改變它代表更好的問題。 –

回答

1

您通過使用positionType="FixRelativeToBottom"屬性

實施例實現這種

<?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="csvTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="601103bc-66ab-45a5-8422-ccb6f3e02ec2"> 
    queryString> 
     <![CDATA[]]> 
    </queryString> 
    <field name="name" class="java.lang.String"/> 
    <field name="age" class="java.lang.String"/> 
    <field name="adress" class="java.lang.String"/> 
    <field name="field1" class="java.lang.String"/> 
    <field name="field2" class="java.lang.String"/> 
    <field name="field3" class="java.lang.String"/> 
    <detail> 
     <band height="60" splitType="Stretch"> 
      <textField isStretchWithOverflow="true"> 
       <reportElement positionType="Float" x="0" y="0" width="100" height="20" uuid="bf6b550c-f37d-4e10-b8dd-1d91c4e6905a"/> 
       <textElement verticalAlignment="Bottom"> 
        <font size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement positionType="Float" x="0" y="20" width="100" height="20" uuid="cbcc18ce-a1c8-4659-b30e-c1a360392b0a"/> 
       <textElement verticalAlignment="Bottom"> 
        <font size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{age}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement positionType="Float" x="0" y="40" width="100" height="20" uuid="ffda046d-87cc-4f51-8568-99c19a54ed7e"/> 
       <textElement verticalAlignment="Bottom"> 
        <font size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{adress}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement positionType="FixRelativeToBottom" x="100" y="0" width="100" height="20" uuid="2110cf81-a71d-45c0-9bd9-d26d69167860"/> 
       <textElement verticalAlignment="Bottom"> 
        <font size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{field1}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement positionType="FixRelativeToBottom" x="100" y="20" width="100" height="20" uuid="2c7fd4ec-324f-4c03-9b13-c3e1bb83d6ad"/> 
       <textElement verticalAlignment="Bottom"> 
        <font size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement positionType="FixRelativeToBottom" x="100" y="40" width="100" height="20" uuid="6371e8da-43d8-43e6-86a3-65bedd87f030"/> 
       <textElement verticalAlignment="Bottom"> 
        <font size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{field3}]]></textFieldExpression> 
      </textField> 
      <line> 
       <reportElement x="0" y="0" width="200" height="1" uuid="719e26b2-88ef-4558-a6d6-2c0589e04638"/> 
      </line> 
     </band> 
    </detail> 
</jasperReport> 

實施例的數據:

+-----------------------------+-----+------------+-------------+-------------+-------------+ 
|   name    | age | adress | field1 | field2 | field3 | 
+-----------------------------+-----+------------+-------------+-------------+-------------+ 
| Very long name that stretch | 12 | Selvarella | field1Value | field2Value | field3Value | 
| Shorty      | 13 | New York | field1Value | field2Value | field3Value | 
+-----------------------------+-----+------------+-------------+-------------+-------------+ 

結果

Result

注意:如果您有多個領域,在同一細節帶延伸,在這些情況下,您可能需要使用報表來獲得正確的佈局可以變得更加複雜。

欲瞭解更多信息請參閱Jasper Report stretch sample