I'm trying to programatically modify the height of a TextArea (JavaFX) as I type so the user sees the entire text without the need to use scrollbars. The TextArea has text-wrapping turned on, and I programatically turn off also both scrollbars in the TextArea's ScrollPane. To calculate the height I create a Text node in the TextArea's change listener and then I read the height of that Text node. I then output the calculated height. I use following code for the start method to calculate the height:
While I'm adding new characters to the first line (e.g. while typing "CodeRanch"), everything works fine, and I get the value "15.9609375" as the text height. Problem occurs when I press backspace (e.g. to get "CodeRanc"). Suddenly the height is "17.0". One could say that 1 pixel is not the end of the world, but with 10 lines in the TextArea the difference is uncomfortable ("159.609375" vs. "170.0").
Do you guys have any idea what is wrong with my code ?