public static void setFont(RSyntaxTextArea textArea, Font font) {
   if (font != null) {
     SyntaxScheme ss = textArea.getSyntaxScheme();
     ss = (SyntaxScheme) ss.clone();
     for (int i = 0; i < ss.getStyleCount(); i++) {
       if (ss.getStyle(i) != null) {
         ss.getStyle(i).font = font;
       }
     }
     textArea.setSyntaxScheme(ss);
     textArea.setFont(font);
   }
 }
  private void changeStyleProgrammatically() {

    // Set the font for all token types.
    setFont(textArea, new Font("Courier New", Font.PLAIN, 12));

    // Change a few things here and there.
    SyntaxScheme scheme = textArea.getSyntaxScheme();
    scheme.getStyle(Token.RESERVED_WORD).background = Color.white;
    scheme.getStyle(Token.RESERVED_WORD).foreground = Color.MAGENTA.darker().darker();

    scheme.getStyle(Token.DATA_TYPE).foreground = Color.blue;
    scheme.getStyle(Token.LITERAL_STRING_DOUBLE_QUOTE).underline = true;
    scheme.getStyle(Token.LITERAL_NUMBER_HEXADECIMAL).underline = true;
    scheme.getStyle(Token.LITERAL_NUMBER_HEXADECIMAL).background = Color.pink;

    scheme.getStyle(Token.COMMENT_EOL).font = new Font("Georgia", Font.ITALIC, 10);

    textArea.revalidate();
  }