Java Utililty Methods JTextArea

List of utility methods to do JTextArea

Description

The list of methods to do JTextArea are organized into topic(s).

Method

voidcopyFontAndMargins(final JTextArea target, final JComponent source)
copy Font And Margins
final Insets insets = source.getInsets();
target.setFont(source.getFont());
target.setMargin(insets);
JPanelcreateTabArea(JTextArea area, int width)
create Tab Area
area.setEditable(false);
area.setOpaque(false);
area.setLineWrap(true);
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
if (width > 0)
    panel.add(Box.createHorizontalStrut(width));
panel.add(area);
...
voiddisplay(JTextArea txtOutput, String text)
display
if (txtOutput != null) {
    txtOutput.setText(txtOutput.getText() + "\n" + text);
} else {
    System.out.println(text); 
intestimatedRows(JTextArea text)
estimated Rows
return (int) (((text.getText().length() / (text.getColumns() > 0 ? text.getColumns() : 80)) + 1
        + text.getText().replaceAll("[^\\n]+", "").length()) / 2);
JTextAreafixTabKeys(JTextArea textArea)
fix Tab Keys
return textArea;
StringgetAreaValue(JTextArea ta)
get Area Value
String ret = ta.getText().trim();
if (!ret.equals("")) {
    return ret;
return null;
JScrollPanegetTextAreaScrollPaneContainer(JTextArea textArea, int nbLines)
get Text Area Scroll Pane Container
JScrollPane ret = new JScrollPane();
textArea.setRows(nbLines);
textArea.setColumns(20);
ret.setViewportView(textArea);
return ret;
DimensiongetTextDimension(JTextArea textArea, Dimension maxDimension)
get Text Dimension
Font font = textArea.getFont();
FontMetrics metrics = textArea.getGraphics().getFontMetrics(font);
int width = metrics.stringWidth(getLongestLine(textArea.getText())) + wPadding;
int height = (metrics.getHeight() + hPadding) * countLines(textArea.getText());
if (width > maxDimension.width)
    width = maxDimension.width;
if (height > maxDimension.height)
    height = maxDimension.height;
...
voidinitLogConsole(final JTextArea textArea)
init Log Console
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));
...
voidinitTextAreaEdit(JTextArea j1)
init Text Area Edit
j1.setLineWrap(true);
j1.setWrapStyleWord(true);