I'm writing an action for a jTextPane's getActionMap that when I type ')' IF at the Caret Position there's a ')' the action overwrite the symbol, ELSE it normally types ')'. 
This is the code:

```
    Action action1 = new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent e) {

                    char bracket = ')';
                    try {
                            int position = jTextPane1.getCaretPosition();
                            if (jTextPane1.getDocument.getText(position,1)== ")") {
                                jTextPane1.getDocument().remove(position, 1);
                                jTextPane1.getDocument().insertString(position, ")", null);
                            } else {
                                jTextPane1.getDocument().insertString(position, ")", null);

                            }

                   } catch (Exception e1) {}
                }

            };

            String key1 = "typed )";
            jTextPane1.getInputMap().put(KeyStroke.getKeyStroke(key1), key1);
            jTextPane1.getActionMap().put(key1, action1);
        }

```

I can't understand why, even if the the boolean of the 'if' is true, it does not go in the if way. Can you help me?