Here you can find the source of setTextSafe(JTextArea textArea, String value)
Parameter | Description |
---|---|
textArea | a parameter |
value | a parameter |
public static void setTextSafe(JTextArea textArea, String value)
//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); } }