• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaFX TextArea - fit height to content  RSS feed

Dusan Vajda
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

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 ?

Windows 7
NetBeans IDE 8.0.1
Java 1.8.0_25

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!