if ((textArea.getCaretPosition() > 0) && (textArea.getText(textArea.getCaretPosition()-1, 1).equals("{"))) { textArea.insertEnterAndIndent(); textArea.setSelectedText("}"); textArea.shiftIndentLeft(); textArea.goToPrevLine(false); textArea.goToEndOfLine(false); textArea.insertEnterAndIndent(); } else { textArea.insertEnterAndIndent(); }