* @param offset Offset position * @return Column number starting in 0. */ public static int getCaretColumn(JTextComponent txtCmp) { return getColumn(txtCmp, txtCmp.getCaretPosition()); } /** * Given an offset, returns the column number in a text component. * * @param offset Offset position * @return Column number starting in 0. */ public static int getColumn(JTextComponent txtCmp, int offset) { return txtCmp.getCaretPosition() - getOffsetStartLine(txtCmp, offset); } /** * Given an offset, returns the offset where the line begins. * * @param offset Offset position. * @return Offset where the line begins. */ public static int getOffsetStartLine(JTextComponent txtCmp, int offset) { return getOffsetStartLine(txtCmp.getDocument(), offset); } /** * Given an offset, returns the offset where the line begins. *