开发者

Calculate possible number of lines in RitchTextField

开发者 https://www.devze.com 2023-01-04 23:31 出处:网络
I have a screen with a RitchTextField added, which has a custom font applied. I want to find the total number of lines that the RitchTextField can hold to avoid vertical scrolling.

I have a screen with a RitchTextField added, which has a custom font applied. I want to find the total number of lines that the RitchTextField can hold to avoid vertical scrolling.

I tried to do this by getting the height of the RichTextField then dividing it by the the height of t开发者_开发百科he font, the problem however is using rtfField.getHeight() always returns the current height of field, and using the screens getHeight() returns the screen size not taking other fields into consideration.

For example:

Screen Size using getHeight() = 360. Font Size using: this.rtfField.getFont().getHeight() = 25 Total Lines ~ 12

However doing a manual count the screen only comfortably displays 8 lines.


Not sure if this is what you're looking for, but I think you want the current height of the field divided by the font height:

int lines = this.rtfField.getHeight() / this.rtfField.getFont().getHeight();
0

精彩评论

暂无评论...
验证码 换一张
取 消