Java tutorial
//package com.java2s; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; import javax.swing.text.Utilities; public class Main { public static int getColumn(int pos, JTextComponent editor) { try { return pos - Utilities.getRowStart(editor, pos) + 1; } catch (BadLocationException e) { e.printStackTrace(); } return -1; } }