I would like to know how to count the number of spaces on a given line before the text actually begins. For ex. if I have this in my JTextPane:

```
public static void main(String[] args) {
    int x = 1;

}

```

after I type 'x = 1;' and press enter, I would like to have the caret on the same indentation as the 'int x = 1;' starts, so I don't have to keep pressing tab or entering spaces manually. Any suggestions?