int colorCode = Integer.parseInt(toWrite.substring( index, index+1)); Color color = getColor(colorCode); if (!istNachkomma) { StyleConstants.setForeground(attributes, color);
try { int colorCode = Integer.parseInt(toWrite.substring( index, index + 1)); Color color = getColor(colorCode); if (!istNachkomma) { StyleConstants.setForeground(attributes, color); } } catch (NumberFormatException nfE2) { StyleConstants.setForeground(attributes, Color.BLUE);
    private SimpleAttributeSet writeString(StyledDocument doc, SimpleAttributeSet attributes, String toWrite){        boolean istNachkomma = false;        boolean parsEnde = false;        int index = 0;        if (toWrite.length()>1){            while (!parsEnde) {                if (toWrite.charAt(index) == ',') {                    istNachkomma = true;                    index++;                    continue;                }                try {                    int colorCode = Integer.parseInt(toWrite.substring(                        index, index+2));                    index += 2;                    Color color = getColor(colorCode);                    if (!istNachkomma) {                        StyleConstants.setForeground(attributes, color);                    }                }                catch (NumberFormatException nfE) {                    if (toWrite.charAt(index + 1) != ',') {                        parsEnde = true;                    }                    try {                        int colorCode = Integer.parseInt(toWrite.substring(                            index, index+1));                        index++;                        Color color = getColor(colorCode);                        if (!istNachkomma) {                            StyleConstants.setForeground(attributes, color);                        }                    }                    catch (NumberFormatException nfE2) {                        parsEnde = true;                        StyleConstants.setForeground(attributes,                            Color.BLACK);                    }                }                catch(StringIndexOutOfBoundsException sioobE){                    parsEnde = true;                    int colorCode = Integer.parseInt(toWrite.substring(                        index, index+1));                    Color color = getColor(colorCode);                    if (!istNachkomma) {                        StyleConstants.setForeground(attributes, color);                    }                    return attributes;                }            }        }        try {            doc.insertString(doc.getLength(),                             toWrite.substring(index),                             attributes);        }        catch (BadLocationException ex) {            ex.printStackTrace();        }        return attributes;    }