且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

itext - setMinimumSize()和setFixedSize()如何交互?

更新时间:2023-11-09 08:36:04

我已经在评论中解释过 setFixedHeight()总是得到偏好。如果在同一行中使用 setMinimumHeight() setFixedHeight(),则定义最小高度以及固定高度,固定高度为准。

I already explained in a comment that setFixedHeight() always gets preference. If you use setMinimumHeight() and setFixedHeight() in the same row, and you define a minimum height along with a fixed height, the fixed height prevails.


  • 如果最小高度设置为30pt且固定高度为60pt,则高度为60pt ,无论在单元格中添加多少内容。

  • 如果最小高度设置为60pt且固定高度为60pt,则高度为60pt,无论内容多少添加到单元格。

  • 如果最小高度设置为120pt且固定高度为60pt,则无论向单元格添加多少内容,高度都将为60pt。

如果定义了不同的固定高度,则采用最高值。例如:如果您有一行,其中一个单元格具有固定高度(例如120磅)高于另一个单元格的固定高度(例如60磅),则最高值(在本例中为120)占优势。

If different fixed heights are defined, the highest value is taken. For instance: if you have a row where one cell has a fixed height (e.g 120 pt) that is higher than the fixed height of another cell (e.g. 60 pt), then the highest value (in this case 120) prevails.

你声称在我写的书中没有提到这一点。请注意,这本书约有600页。我写的很多文字都是由出版商编辑的。否则这本书将会有一千多页。

You claim that this isn't mentioned in the book I wrote. Please note that the book counts about 600 pages. A lot of text I wrote was edited away by the publisher. Otherwise the book would have been a thousand pages and more.

您可以写一个小的测试示例,例如 FixedHeightCell 示例。请查看生成的PDF 。在行D中,所有单元具有60磅的固定高度。在E行中,大多数单元格的固定高度也为60,但第4列中的单元格固定高度为120,因此行的高度为120.然后是F行,固定高度为60 pt,最小高度120磅。虽然我们添加的文本不适合第2列中的单元格,但内容会被截断。

You could have written a small test example, such as the FixedHeightCell example. Please take a look at the resulting PDF. In row D all the cells have a fixed height of 60 pt. In row E, most cells also have a fixed height of 60, but the cell in column 4 has a fixed height of 120, hence the height of the row is 120. Then there's row F, with a fixed height of 60 pt and a minimum height of 120 pt. Although we add text that doesn't fit the cell in column 2, the content is truncated.