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

JTextAreamakeLabelStyle(JTextArea textArea)
Make a JTextArea to look like a JLabel
if (textArea == null)
    return null;
textArea.setEditable(false);
textArea.setCursor(null);
textArea.setOpaque(false);
textArea.setFocusable(false);
return textArea;
JTextAreamakeTabMoveFocus(JTextArea textArea)
Based on Green, Roedy.
textArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
        new HashSet(Arrays.asList(new Object[] { KeyStroke.getKeyStroke("TAB") })));
textArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
        new HashSet(Arrays.asList(new Object[] { KeyStroke.getKeyStroke("shift TAB") })));
return textArea;
OutputStreamout(final JTextArea ta)
out
return new OutputStream() {
    public void write(int b) throws IOException {
        ta.append(String.valueOf((char) b));
};
voidpreventInputingNewLineOnTextArea(JTextArea txe, AbstractAction actionOnEnter)
prevent Inputing New Line On Text Area
if (actionOnEnter == null) {
    actionOnEnter = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
    };
txe.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), actionOnEnter);
...
voidprintExceptionInfo(Exception e, JTextArea console)
print Exception Info
console.append(e.getMessage());
printStackTrace(e, console);
voidprintInfo(JTextArea txtInfo, String infoString)
print Info
if (txtInfo != null) {
    txtInfo.append(infoString);
    try {
        txtInfo.setCaretPosition(txtInfo.getLineStartOffset(txtInfo.getLineCount() - 1));
    } catch (BadLocationException e) {
} else
    System.out.println(infoString);
...
voidprintInTextArea(JTextArea log, String[] toPrint)
print In Text Area
for (int i = 0; i < toPrint.length; i++)
    log.append(toPrint[i] + NEWLINE);
voidprintStackTrace(Exception e, JTextArea console)
print Stack Trace
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
console.append(pw.toString());
PrintStreamprintStream(final JTextArea ta)
print Stream
return new PrintStream(out(ta)) {
    public void println(String line) {
        ta.append(line + "\n");
};
voidregisterUndoManager(JTextArea textArea)
register Undo Manager
final UndoManager undo = new UndoManager();
Document doc = textArea.getDocument();
doc.addUndoableEditListener(new UndoableEditListener() {
    public void undoableEditHappened(UndoableEditEvent evt) {
        undo.addEdit(evt.getEdit());
});
textArea.getActionMap().put("Undo", new AbstractAction("Undo") {
...