Examples: RichTextStyle class, and Bold, Color, Effects, Font, FontSize, Italic, Parent, StrikeThrough, and Underline properties

This agent writes a text using various styles.

import lotus.domino.*;
public class JavaAgent extends AgentBase {
  public void NotesMain() {
    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      // (Your code goes here) 
      Database db = agentContext.getCurrentDatabase();
      Document doc = db.createDocument();
      Item subject = doc.replaceItemValue("Subject", 
       "Rich text tab");
      RichTextItem body = doc.createRichTextItem("Body");
      // Create and define styles
      RichTextStyle header = session.createRichTextStyle();
        header.setBold(RichTextStyle.YES);
        header.setColor(RichTextStyle.COLOR_DARK_BLUE);
        header.setEffects(RichTextStyle.EFFECTS_SHADOW);
        header.setFont(RichTextStyle.FONT_ROMAN);
        header.setFontSize(14);
      RichTextStyle byline = session.createRichTextStyle();
        byline.setBold(RichTextStyle.NO);
        byline.setColor(RichTextStyle.COLOR_BLACK);
        byline.setEffects(RichTextStyle.EFFECTS_NONE);
        byline.setItalic(RichTextStyle.YES);
        byline.setFontSize(10);
      RichTextStyle normal = session.createRichTextStyle();
        normal.setItalic(RichTextStyle.NO);
        normal.setUnderline(RichTextStyle.NO);
        normal.setStrikeThrough(RichTextStyle.NO);
      RichTextStyle underline = session.createRichTextStyle();
        underline.setUnderline(RichTextStyle.YES);
      RichTextStyle strike = session.createRichTextStyle();
        strike.setStrikeThrough(RichTextStyle.YES);
      // Generate Body item
      body.appendStyle(header);
        body.appendText("Header");
        body.addNewLine();
      body.appendStyle(byline);
        body.appendText("by " + 
          byline.getParent().getCommonUserName());
        body.addNewLine(2);
      body.appendStyle(normal);
        for (int i=0; i<11; i++)
          body.appendText("Sentence of normal text. ");
      body.appendStyle(underline);
        body.appendText("Underlined text.");
      body.appendStyle(normal);
        for (int i=0; i<11; i++)
          body.appendText(" Sentence of normal text.");
          body.appendText(" ");
      body.appendStyle(strike);
        body.appendText("Strikethrough text.");
      body.appendStyle(normal);
        for (int i=0; i<11; i++)
          body.appendText(" Sentence of normal text.");
    // Save the document
      doc.save(true, true);
    } catch(NotesException e) {
      System.out.println(e.id + " " + e.text);
      e.printStackTrace();
    }
  }
}