textArea.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
try {
// Show the caret's position in the status bar.
int row = textArea.getLineOfOffset(e.getDot());
int column = e.getDot() - textArea.getLineStartOffset(row);
statusLabel.setText("Line: " + (row + 1) + ", Column: " + column);
} catch (Exception e2) {
e2.printStackTrace();
}
}
});