Java Textarea ScrollPane

后端 未结 4 1868
旧巷少年郎
旧巷少年郎 2021-01-28 23:24

I have created a textarea, and i need a scrollbar applied to the textarea when necessary (when the text gets too long down and it cant be read anymore).

this is the code

4条回答
  •  花落未央
    2021-01-28 23:37

    Make sure that the preferredSize and the viewportSize are the same. The scrollpane will size itself with the preferred size of the textArea, and this can cause the scrollbars to disappear if the preferred size of the text area is large enough to display itself.

    Again, please read the JTextArea and JScrollPane tutorials.

    textArea.setPreferredSize(new Dimension(456, 255));
    textArea.setPreferedScrollableViewportSize(new Dimension(456, 255));
    

提交回复
热议问题