Jasper-report:如何使用java代码拉伸文本字段

Gir*_*h K 5 java jasper-reports

我在我的应用程序中使用jasper报告作为报告工具.我想通过使用java代码创建一个动态文本字段.有没有办法实现这一点?你能给我一些建议吗?

Sab*_*thy 4

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

\n\n

参考这个

\n\n
Dynamic Text Fields\n\nText 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.\nTo 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.\n\nNotes:\n\n    Text fields with delayed evaluation do not stretch to acquire all the expression\xe2\x80\x99s 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.\n    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.\n\nText Truncation\n\nIn 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:\n\n    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.\n    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.\n    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.\n\n\n\nText Truncation and Element Stretching Examples\n\nThis sample provides some examples of element stretching and text truncations. One can see various combinations between different elements stretching attributes (positionType, stretchType, isStretchWithOverflow):\n\n  <elementGroup>\n  <line>\n    <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="5" y="5" \n      width="1" height="16" isPrintWhenDetailOverflows="true"/>\n    <graphicElement/>\n  </line>\n  <textField isStretchWithOverflow="true">\n    <reportElement x="10" y="5" width="100" height="16" isRemoveLineWhenBlank="true"/>\n    <textElement textAlignment="Justified">\n      <font size="12"/>\n    </textElement>\n    <textFieldExpression class="java.lang.String">\n      This is a FIRST long chunk of text that will cause the text field to stretch \n      outside its defined height and force other elements to move downwards.\n    </textFieldExpression>\n  </textField>\n  <line>\n    <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="135" y="5" \n      width="1" height="16" isPrintWhenDetailOverflows="true"/>\n    <graphicElement/>\n  </line>\n  </elementGroup>\n\nor text truncation properties:\n\n  <staticText>\n    <reportElement x="145" y="205" width="130" height="100">\n      <property name="net.sf.jasperreports.text.truncate.at.char" value="true"/>\n    </reportElement>\n    <textElement>\n      <font size="10"/>\n    </textElement>\n      <text>Text elements can also be truncated at the last character that fits \n        the element reserved area; the behavior is triggered by setting a property. \n        This sentence might not fit fully in the space reserved for the element.\n      </text>\n  </staticText>\n
Run Code Online (Sandbox Code Playgroud)\n

  • 您能解释更多吗?或者贴上屏幕截图吗? (2认同)