private void insertTabAsSpace(KeyEvent event, JTextComponent component) {
        try {
            int caretPostion = component.getCaretPosition() - 1;
            component.getDocument().remove(caretPostion, 1);
            component.getDocument().insertString(caretPostion, "    ", null);
            event.consume();
        } catch (BadLocationException ex) {
            System.out.println("Could not insert a tab: " + ex.getMessage());
        }
    }