views:

28

answers:

1

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 the 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.

+1  A: 

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();
Matt
This is what I am trying to do however rtfField's height changes with the number of lines inserted up to its max height, which makes it impossible to determine how many lines to fill in from the start. I've tried using the layout containers maxHeight however that in this case returns 330, font height 25 so you get330 / 25 = 13.2. However the box itself only seems to support 8 lines at this height.
SS44
rtfField's height changes? That doesn't sound like it's supposed to happen. Not sure if this will help, but you might be able to set maximum and minimum dimensions to be the same, and that should keep the height from changing.
Matt
Thanks, I tried to set the max height, but again this will differ on a device by device bases, I also tried setting the container flag so that it uses the max height, but even that without any text defaults to the font size (single line).
SS44