Java – limits the size of the jtextarea to the size of its text

I have a fixed size (300 x 33) jtextarea with line feed enabled. I have added it to JPanel Whenever you type in it and pass through the last visible line (the second in this case), the text continues outside the view of the text area and is hidden

Is there a limit to the size of the text area rather than the number of characters it contains (making it dependent on the different space occupied by each character of different fonts)?

Edit: I forgot to mention that not fixing the size of jtextarea and providing row and column numbers in the constructor will cause the text area to stretch and fill the JPanel holding it I believe this is because the panel layout is @ R_ 335_ 2419@Layout.

Solution

You should not fix the size of jtextarea Instead, initialize it by calling the constructor with the appropriate column and row number parameters and place it in the JScrollPane, so if the text increases, it will not be lost

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>