private void addStyledText(String text, Style style) {
   try {
     doc.insertString(doc.getLength(), text, style);
   } catch (BadLocationException ble) {
     ble.printStackTrace();
   }
 }
    private void setOutput() {
      String[] styles = new String[traceLines.length];
      Pattern p1 = Pattern.compile("uk.co.essarsoftware.par.", Pattern.LITERAL);
      for (int i = 0; i < styles.length; i++) {
        styles[i] = (p1.matcher(traceLines[i]).find() ? "red" : "normal");
      }

      StyledDocument doc = getStyledDocument();
      try {
        for (int i = 0; i < traceLines.length; i++) {
          doc.insertString(doc.getLength(), traceLines[i] + "\n", doc.getStyle(styles[i]));
        }
      } catch (BadLocationException ble) {
        setText("Unexpected exception loading stack trace");
      }
    }