Dynamically resize textarea to fit content

后端 未结 3 1269
梦毁少年i
梦毁少年i 2021-01-27 03:00

Here is a textarea I have put in my program using netbeans. The first image shows what the textarea looks like when I run the program. The second image is show the textarea afte

3条回答
  •  灰色年华
    2021-01-27 03:33

    I wouldn't use JTextArea for anything except prototyping. It has the bitter functionality of notepad. But it's up to you.

    I would use a JEditorPane or JTextPane. I know you can't size it based on character size but that's for the best. For word wrap, you can do setContentType("text/html"); and wrap the text in <'p><'/p> tags.

    (Note you still use JScrollPane for scrolling. In fact, the scroll pane works for any component)

    See the differences: http://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html

提交回复
热议问题