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
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));