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

voidsetCaretPosition(int i, int j, JTextArea jtextarea)
set Caret Position
if (i < 0 || j < 0)
    return;
StringBuffer stringbuffer = new StringBuffer(jtextarea.getText());
int k = 0;
int l;
for (l = stringbuffer.length(); i > 0 && k < l; k++)
    if (stringbuffer.charAt(k) == '\n')
        i--;
...
voidsetCaretPosition(JTextArea ta)
set Caret Position
ta.setCaretPosition(ta.getDocument().getLength());
voidsetCeil(final JTextArea textArea)
set Ceil
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        JViewport v = (JViewport) textArea.getParent();
        v.setViewPosition(new Point(0, 0));
});
voidsetModelValue(JTextArea ta, String value)
set Model Value
if (value != null) {
    ta.setText(value);
voidsetTextSafe(JTextArea textArea, String value)
set the text of a JTextArea without moving the caret normally, setting the text would trigger am event that scrolls the Text Area into view.
Caret caret = textArea.getCaret();
caret.setDot(0);
textArea.setCaret(null);
textArea.setText(value);
textArea.setCaret(caret);
voidshowMemo(JTextArea memo, boolean visible)
show Memo
memo.setVisible(visible);
if (memo.getParent() instanceof JScrollPane)
    memo.getParent().setVisible(visible);
else if (memo.getParent().getParent() instanceof JScrollPane)
    memo.getParent().getParent().setVisible(visible);
JTextAreatextAreaAsLabel(JTextArea textArea)
This will allow selection and copy to work but still retain the label look
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textComponentAsLabel(textArea);
return textArea;
voidvalidarArticuloDescripcion(JTextArea descripcion, KeyEvent evt)
validar Articulo Descripcion
char ch = evt.getKeyChar();
if ((descripcion.getText().length() == 500)
        || ((ch > '9' || ch < '0') && (ch > 'z' || ch < 'a') && (ch > 'z' || ch < 'A')
                && (ch != KeyEvent.VK_SPACE) && ch != KeyEvent.VK_COMMA && ch != KeyEvent.VK_PERIOD)) {
    evt.consume();
voidvalidateView(JTextArea view)
Validates that the given view is not null and has a Document .
if (view == null || view.getDocument() == null) {
    throw new IllegalArgumentException("Parameter view must not be null and must have a Document.");