You must put your JTextArea in the JScrollPane . This will keep your row size intact and will have the added benefit of allowing the user to navigate through the input. If you want, you can set scrollpane to never show. You can still rely on the JTextArea component to calculate the row height and then the preferred component height.
The setRows call that you use to indicate the number of lines visible on your display is a property that is supported for working with JScrollPane , as described in the JTextArea JavaDoc :
java.awt.TextArea has two rows * properties and columns that are used to determine the preferred size. JTextArea uses these properties to indicate the preferred viewport size, if it is inside a JScrollPane, to match the functionality provided by java.awt.TextArea. JTextArea has the preferred size needed to display all the text, so that it functions correctly inside JScrollPane.
* my emphasis
source share