如何通过某些组中最长的文本自动设置字段的最小宽度

发布于 2024-12-27 22:11:43 字数 338 浏览 2 评论 0原文

我使用 iReport 创建报告,我想知道是否有办法设置“光学分组字段”的宽度。应将它们设置为仍显示最长文本的最小尺寸。我的左侧有静态文本,右侧有文本字段。此文本字段设置为宽度 150 并向右对齐,但我想设置较小的尺寸以消除空格。

考虑这样的事情

   Name:            Paul
Surname:         Smither  

,并希望自动

   Name:    Paul
Surname: Smither 

等可以小于预设尺寸,但不能更大。

有办法吗??甚至某些组件

I use iReport to create reports, and I would like to know if there is a way to set the width of "optically grouped fields". They should be set to the minimal size that still displays longest text. I have Static Text on left side and Text Field right of them. This Text Fields are set to the width 150 and alignment to right, but I'd like to set smaller size to wipe out white spaces.

Consider some thing like this

   Name:            Paul
Surname:         Smither  

And want automatically to

   Name:    Paul
Surname: Smither 

etc. can be smaller then preset size but no bigger.

Is there a way?? even some component

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人迟暮 2025-01-03 22:11:43

如果不使用 Java 框架,您无法动态更改元素宽度。

引用自 JasperReports 终极指南

元素大小

宽度和高度属性是强制性的,代表尺寸
以像素为单位测量的报表元素。其他元素拉伸
设置可能会指示报告引擎忽略指定的
元素高度。即使在这种情况下,属性仍然是强制性的
因为即使动态计算高度,该元素也会
不能小于原来指定的高度。

您可以阅读这篇文章以更好地了解更改元素大小。

You cannot change the element width dynamically without using Java frameworks.

The quote from JasperReports Ultimate Guide:

ELEMENT SIZE

The width and height attributes are mandatory and represent the size
of the report element measured in pixels. Other element stretching
settings may instruct the reporting engine to ignore the specified
element height. Even in this case, the attributes remain mandatory
since even when the height is calculated dynamically, the element will
not be smaller than the originally specified height.

You can read this article for better understanding the mechanism of changing the element size.

木格 2025-01-03 22:11:43

如果它确实只是来自数据集中同一行的几个字段,那么您可以将某些内容组合在一起。

  • 使用等宽字体
  • 将字符串设置为 N 个空格来定义最大字段长度。例如:
    $P{MaxLengthString} 默认值为 10 个空格:" "
  • 将字段文本从 $F{FirstName} 更改为:

    $P{MaxLengthString}.substring(
      $P{MaxLengthString}.length() + $F{FirstName}.length() - java.lang.Math.max($F{FirstName}.length(), $F{LastName}.length())
    ) + $F{名字}
    

那是...呃...有点复杂。它仅适用于等宽字体。我不敢相信我真的建议了这个。不要这样做。 (但它应该有效。)

If it's genuinely just a couple of fields that come from the same row in the dataset, then you could hack something together.

  • Use a monospace font
  • Define your maximum field length with a String set to N spaces. For example:
    $P{MaxLengthString} default value is 10 spaces: " "
  • Change your field text from $F{FirstName} to this:

    $P{MaxLengthString}.substring(
      $P{MaxLengthString}.length() + $F{FirstName}.length() - java.lang.Math.max($F{FirstName}.length(), $F{LastName}.length())
    ) + $F{FirstName}
    

That is... er... a bit more complex. And it only works with monospace fonts. And I can't believe I really suggested this. Don't do it. (But it ought to work.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文