相关文章推荐
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
I have a JTextArea and set its contents dynamically. I need to dynamically change the height of the JTextArea depending on the number of rows of text in it.
I came up with the idea of getting the desired height value by multiplying the row height the number of rows as follows (ta is my JTextArea):
However, the compiler gives the the following error:
[tt]getRowHeight() has protected access in javax.swing.JTextArea[/tt]
Is there a way to obtain the row height, or do I need to come up with a new solution?
I'm using the null layout manager.
Thanks!
You would get access to that method if you were to extend the JTextArea class. Maybe overriding the 'setText' method could be a place to recalculate the controls size using the formula you've got. This may work since you're using a 'null' layout manager. If you were to try to use this technique with a layout manager, it probably wouldn't due to the JTextArea's container requiring a revalidate{} to cater for the controls new size.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies. Accept Learn more…
 
推荐文章