Java JTextArea initLogConsole(final JTextArea textArea)

Here you can find the source of initLogConsole(final JTextArea textArea)

Description

init Log Console

License

Apache License

Declaration

public static void initLogConsole(final JTextArea textArea) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import javax.swing.JTextArea;

import org.springframework.util.Log4jConfigurer;
import org.springframework.util.ResourceUtils;

public class Main {
    public static void initLogConsole(String workingDirSystemProperty, String logFileClassPath, long refreshInteval)
            throws FileNotFoundException {
        Log4jConfigurer.setWorkingDirSystemProperty(workingDirSystemProperty);
        Log4jConfigurer.initLogging(ResourceUtils.CLASSPATH_URL_PREFIX + logFileClassPath, refreshInteval);
    }/*from   w ww .j  a  v a 2s . co  m*/

    public static void initLogConsole(final JTextArea textArea) {
        OutputStream textAreaStream = new OutputStream() {
            public void write(int b) throws IOException {
                clearTextArea(textArea);
                textArea.append(String.valueOf((char) b));
            }

            public void write(byte b[]) throws IOException {
                clearTextArea(textArea);
                textArea.append(new String(b));
            }

            public void write(byte b[], int off, int len) throws IOException {
                clearTextArea(textArea);
                textArea.append(new String(b, off, len));
            }
        };
        PrintStream myOut = new PrintStream(textAreaStream);
        System.setOut(myOut);
        System.setErr(myOut);
    }

    private static void clearTextArea(JTextArea textArea) {
        if (textArea.getLineCount() > 200) {
            textArea.setText("");
        }
    }
}

Related

  1. estimatedRows(JTextArea text)
  2. fixTabKeys(JTextArea textArea)
  3. getAreaValue(JTextArea ta)
  4. getTextAreaScrollPaneContainer(JTextArea textArea, int nbLines)
  5. getTextDimension(JTextArea textArea, Dimension maxDimension)
  6. initTextAreaEdit(JTextArea j1)
  7. makeLabelStyle(JTextArea textArea)
  8. makeTabMoveFocus(JTextArea textArea)
  9. out(final JTextArea ta)