Java JTextArea setTextSafe(JTextArea textArea, String value)

Here you can find the source of setTextSafe(JTextArea textArea, String value)

Description

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.

License

Open Source License

Parameter

Parameter Description
textArea a parameter
value a parameter

Declaration

public static void setTextSafe(JTextArea textArea, String value) 

Method Source Code


//package com.java2s;
/*/*ww w  . j av a2s  . c  o m*/
 * This file is part of the Jose Project
 * see http://jose-chess.sourceforge.net/
 * (c) 2002-2006 Peter Sch?fer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

import javax.swing.*;
import javax.swing.text.Caret;

public class Main {
    /**
     * 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.
     * If we don't want scrolling, we need to avoid the caret event.
     *
     * @param textArea
     * @param value
     */
    public static void setTextSafe(JTextArea textArea, String value) {
        Caret caret = textArea.getCaret();
        caret.setDot(0);
        textArea.setCaret(null);
        textArea.setText(value);
        textArea.setCaret(caret);
    }
}

Related

  1. registerUndoManager(JTextArea textArea)
  2. setCaretPosition(int i, int j, JTextArea jtextarea)
  3. setCaretPosition(JTextArea ta)
  4. setCeil(final JTextArea textArea)
  5. setModelValue(JTextArea ta, String value)
  6. showMemo(JTextArea memo, boolean visible)
  7. textAreaAsLabel(JTextArea textArea)
  8. validarArticuloDescripcion(JTextArea descripcion, KeyEvent evt)
  9. validateView(JTextArea view)