テキストのフローがある IlvDocument の作成

ここでは、テキスト・フローがある印刷フレームワークの使用方法を説明する簡単な例を示します。
テキスト・フロー例を印刷するには、以下の手順に従います。
  1. IlvPrintableDocument オブジェクトを作成します。
  2. IlvFlow オブジェクトを作成します。
  3. IlvFlow オブジェクトにテキストとイメージを追加します。
  4. テキストのスタイルとパラグラフ整列を設定します。
  5. 印刷コントローラーを作成して使用します。
  6. 最後に、ユーザー・インターフェース・コンポーネントによる、作成ドキュメントのプレビューを行います。
コード例を次に示します。
テキスト・フローを使用してドキュメントを作成する
 // Creates the document.
 IlvPrintableDocument document 
= new IlvPrintableDocument("A Test Document");
   
// Gets the flow to add text and images.
IlvFlow flow = document.getFlow();

// Sets the style of text and paragraph alignment
// for the title.
IlvFlow.TextStyle style = new IlvFlow.TextStyle();
style.setFont(new Font("Helvetica", Font.BOLD, 20));
style.setAlignment(IlvFlow.TextStyle.CENTER_ALIGNMENT);
flow.setTextStyle(style);

// Adds the title text.
flow.add("The Printing Framework Document Model");

flow.newLine();

// Sets the style of text for the next paragraph.
style.setAlignment(IlvFlow.TextStyle.LEFT_ALIGNMENT);
style.setFont(new Font("Helvetica", Font.PLAIN, 16));
flow.setTextStyle(style);

flow.newLine();
flow.add("The document model provides a structure to define a multiple-page document to be printed. The document model allows you to concentrate your efforts on creating your printable document without worrying about how the document is previewed and printed. The printing framework previews and prints the document for you.");
 
flow.newLine();
flow.newLine();
flow.add("The following figure shows the relationship between the main classes in the document model:");
flow.newLine();

try {
  
    // Loads an image to add.
    Image image = IlvUtil.GetImageFromFile(Class.forName("demos.print.PrintExample"), "model.gif");

    // Adds the image to the flow.
    flow.add(image, IlvFlow.TOP_ALIGNMENT);

  } catch (Exception e) {
}

// Creates the print controller.
IlvPrintingController controller = new IlvPrintingController(document);
    
// Previews the document.
controller.setPreviewMode(IlvPrintPreviewPanel.CONTINUOUS_MODE);
controller.printPreview(JOptionPane.getRootFrame());
画面には以下のように表示されます。
flow.gif
テキスト・フローのあるドキュメント