java - 碧 Jade 报告 : How can I stretch a text-field by using java code

标签 java jasper-reports

<分区>

我在我的应用程序中使用 jasper 报告作为报告工具。我想使用 java 代码制作一个动态文本字段。有什么办法可以实现吗?你能给我一些建议吗?

最佳答案

您可以做一件事来调整动态字段的大小。打开文本字段表达式写如下“包含内容”+ ${parameterName}。

Refer this

Dynamic Text Fields

Text fields are elements with specific stretch behavior. When their content does not fit within their boundaries, the engine either truncate them to fit within the initial dimensions, or recalculates their height in order to make room for all the text content. Text fields are the elements which require dynamic text measurement at runtime and then start the element size recalculation for all the elements in the affected section. After text fields are measured and stretched, all other elements in the same section are resized or repositioned, according to their own stretching attributes.
To decide whether a text field content gets truncated at runtime or no, one can use the isStretchWithOverflow attribute in the <textField/> element. If true, then the text field height will be automatically increased until the whole text content can be displayed. The default value is false.

Notes:

    Text fields with delayed evaluation do not stretch to acquire all the expression’s content. This is because the text element height is calculated when the report section is generated, and even if the engine comes back later with the text content of the text field, the element height will not adapt, because this would ruin the already created layout.
    When filling report templates horizontally, dynamic text fields inside the detail section do not stretch to their entire text content, because this might cause misalignment on the horizontal axis of subsequent detail sections. The detail band actually behaves the same as the page and column footers, preserving its declared height when horizontal filling is used.

Text Truncation

In some situations preserving the initial layout takes precedence over any other runtime modification. If the text content gets wider than the available area, then a truncation mechanism is applied in order to keep only the part of text which fits within the original boundaries. If one choose the text truncation as desired behavior for a text element, a series of custom properties can be set to indicate how to perform the truncation:

    net.sf.jasperreports.text.truncate.at.char - Flag that determines whether text elements are to be truncated at the last character that fits. By default, when the entire text of a text element does not fit the element's area, the text is truncated at the last word that fits the area.
    net.sf.jasperreports.text.truncate.suffix - Contains a suffix for the truncated text. The suffix is appended to the text when truncation occurs. If the property is not defined, no suffix will be used when the text is truncated.
    net.sf.jasperreports.print.keep.full.text - Flag to determine whether the fill process must preserve the original text for text elements that are not able to fit their entire contents. When this property is set, the engine saves the original text in the JRPrintText print text object, along with the index at which the text is to be truncated by the print object. The original text can be then entirely exported to layout insensitive formats such as CSV, XML, Excel.



Text Truncation and Element Stretching Examples

This sample provides some examples of element stretching and text truncations. One can see various combinations between different elements stretching attributes (positionType, stretchType, isStretchWithOverflow):

  <elementGroup>
  <line>
    <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="5" y="5" 
      width="1" height="16" isPrintWhenDetailOverflows="true"/>
    <graphicElement/>
  </line>
  <textField isStretchWithOverflow="true">
    <reportElement x="10" y="5" width="100" height="16" isRemoveLineWhenBlank="true"/>
    <textElement textAlignment="Justified">
      <font size="12"/>
    </textElement>
    <textFieldExpression class="java.lang.String">
      This is a FIRST long chunk of text that will cause the text field to stretch 
      outside its defined height and force other elements to move downwards.
    </textFieldExpression>
  </textField>
  <line>
    <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="135" y="5" 
      width="1" height="16" isPrintWhenDetailOverflows="true"/>
    <graphicElement/>
  </line>
  </elementGroup>

or text truncation properties:

  <staticText>
    <reportElement x="145" y="205" width="130" height="100">
      <property name="net.sf.jasperreports.text.truncate.at.char" value="true"/>
    </reportElement>
    <textElement>
      <font size="10"/>
    </textElement>
      <text>Text elements can also be truncated at the last character that fits 
        the element reserved area; the behavior is triggered by setting a property. 
        This sentence might not fit fully in the space reserved for the element.
      </text>
  </staticText>

关于java - 碧 Jade 报告 : How can I stretch a text-field by using java code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20853029/

相关文章:

java - 似乎无法让 TableModelListener 工作

java - 如何将Uri图片转成Base64?

java - JUnit 的不同风格?

java - 如何通过 Selenium 关闭对话框?

java - 在不同的细节带中迭代相同的数据

java - 如何使用JavaBeans作为数据源显示嵌套对象?

jasper-reports - JasperReport - 同一报告中的不同方向(横向和纵向)

jasper-reports - BIRT/Jasper/Pentaho - 临时报告?

java - 我可以引用 Spring 中的嵌套 bean 吗?

java - 如何显示相对于日期的上个月的最后一天?