

JScrollPane areaScrollPane = new JScrollPane(textArea) ĪtVerticalScrollBarPolicy(ĪtPreferredSize(new Dimension(250, 250)) Note that the text system uses the '\n' character internally to represent newlines for details, see the API documentation for The following code adds text to the text area.

It is still selectable and the user can copy data from it, but the user cannot change the text area's contents directly. The code setEditable(false) makes the text area uneditable. See How to Use Scroll Panes if you want further information. The JScrollPane constructor shown in the preceding snippet sets up the text area for viewing in a scroll pane, and specifies that the scroll pane's scroll bars should be visible when needed. Without the creation of the scroll pane, the text area would not automatically scroll. The scroll pane that contains the text area pays attention to these hints when determining how big the scroll pane should be. The two arguments to the JTextArea constructor are hints as to the number of rows and columns, respectively, that the text area should display. JScrollPane scrollPane = new JScrollPane(textArea)
