Here you can find the source of adjustToText(JTextArea testString)
static void adjustToText(JTextArea testString)
//package com.java2s; import javax.swing.JTextArea; public class Main { static void adjustToText(JTextArea testString) { testString.setColumns(columns(testString)); testString.setRows(estimatedRows(testString)); }//from w w w .j a va 2 s . c o m static int columns(JTextArea testString) { return Math.min((int) (testString.getText().length() * 0.66), 80); } static int estimatedRows(JTextArea text) { return (int) (((text.getText().length() / (text.getColumns() > 0 ? text.getColumns() : 80)) + 1 + text.getText().replaceAll("[^\\n]+", "").length()) / 2); } }