Here you can find the source of getRow(int pos, JTextComponent editor)
public static int getRow(int pos, JTextComponent editor) throws BadLocationException
//package com.java2s; /*//from w ww . j ava2 s. c om * Copyright (c) 2011 - 2012. Elega9t Ltd. All rights reserved. * ELEGA9T PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.Copyright (c) 2011 - 2012. Elega9t Ltd. All rights reserved. */ import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; import javax.swing.text.Utilities; public class Main { public static int getRow(int pos, JTextComponent editor) throws BadLocationException { int rn = (pos == 0) ? 1 : 0; int offs = pos; while (offs > 0) { offs = Utilities.getRowStart(editor, offs) - 1; rn++; } return rn; } }