Java JTextArea adjustToText(JTextArea testString)

Here you can find the source of adjustToText(JTextArea testString)

Description

adjust To Text

License

Open Source License

Declaration

static void adjustToText(JTextArea testString) 

Method Source Code


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

Related

  1. addMessageLogger(JTextArea t)
  2. addStyle(JTextArea textArea, String labelName, boolean isBorder)
  3. appendNewLine(final JTextArea textArea, final String line)
  4. applyDefaultProperties(final JTextArea comp)
  5. attachSimpleUndoManager(JTextArea jta)
  6. blockUncomment(JTextArea scriptPanel)