I've done a ton of research regarding this issue, but I haven't had any luck with anything I've found. It's a major roadblock in the application I'm developing.
My application has a Form, which contains a JScrollPane. After adding a JTextArea inside the JScrollPane, I see that when I run the program and type in the JTextArea, it is accompanied by scrollbars when the JTextArea overflows with text. Even if I set the scrollbar policy to 'NEVER', it simply overflows and moves the current text up.
What I would like my JTextArea to do is simply grow in size (vertically/height wise) when the textual content becomes too much to fit in the box. This seems to be a fairly simple concept - something we see, even in MS Paint. When a text object is added, it is a specific size. Then, as text as entered, each new line makes the text field larger, vertically. The text field can also be resized manually by the user. This feature isn't something I will need to do right now.
I have tried getting and setting the size using jTextArea1.getSize()
, as well as the row count using jTextArea1.getRows()
, line count using jTextArea1.getLineCount()
, and the preferred size using jTextArea1.getPreferredSize()
.
I have tried to use these returned variables to set the size using jTextArea1.setSize()
, jTextArea1.setRows()
, jTextArea1.setLineCount()
, and jTextArea1.setPreferredSize()
, none of which have worked. Any advice on what I'm doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…