Java JTextArea setCaretPosition(int i, int j, JTextArea jtextarea)

Here you can find the source of setCaretPosition(int i, int j, JTextArea jtextarea)

Description

set Caret Position

License

Open Source License

Declaration

public static void setCaretPosition(int i, int j, JTextArea jtextarea) 

Method Source Code

//package com.java2s;
/*/* www .  ja  v a2  s.c o m*/
 * Copyright (C) 2012 Marco Ratto
 *
 * This file is part of the project MQJExplorer.
 *
 * MQJExplorer 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
 * any later version.
 *
 * MQJExplorer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MQJExplorer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import javax.swing.JTextArea;

public class Main {
    public static void setCaretPosition(int i, int j, JTextArea jtextarea) {
        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--;

        if (i > 0)
            return;
        k += j;
        if (k > l)
            k = l;
        jtextarea.setCaretPosition(k);
    }
}

Related

  1. printInfo(JTextArea txtInfo, String infoString)
  2. printInTextArea(JTextArea log, String[] toPrint)
  3. printStackTrace(Exception e, JTextArea console)
  4. printStream(final JTextArea ta)
  5. registerUndoManager(JTextArea textArea)
  6. setCaretPosition(JTextArea ta)
  7. setCeil(final JTextArea textArea)
  8. setModelValue(JTextArea ta, String value)
  9. setTextSafe(JTextArea textArea, String value)