Using a Position in a JTextComponent
import javax.swing.JTextArea; import javax.swing.text.Document; import javax.swing.text.JTextComponent; import javax.swing.text.Position; public class Main { public static void main(String[] argv) throws Exception{ JTextComponent textComp = new JTextArea(); Document doc = textComp.getDocument(); Position p = null; int location = 3; p = doc.createPosition(location); } }