Okay, the carriage return messed stuff a bit up... (and i discovered the CaretListener btw )
This seems to work... i've tested it for about 30 seconds so it's GOT to be fail-proof :D
public class Test extends JFrame {
private JLabel label;
public Test() {
super();
final JEditorPane ePane = new JEditorPane();
ePane.addCaretListener(new CaretListener(){
public void caretUpdate(CaretEvent e) {
int pos = e.getDot();
int row = 0, column=0;
String text = ePane.getText().replaceAll("\r", "");
if(pos+1<=text.length()){
text = text.substring(0, pos+1);
column--;
}
while (text.contains("\n")) {
row++;
int start = text.indexOf("\n");
if (text.length() - start >= 1) {
text = text.substring(start+1, text.length());
}
}
column += text.length();
label.setText(row + ", " + column + " (" + pos + ")");
}
});
label = new JLabel();
add(ePane);
add(label, BorderLayout.SOUTH);
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
Test test = new Test();
}
}