プログラム自体に渡される文字列を印刷するコードがあります。ここでは、印刷ボタンでこのコードを呼び出して、ハード コピーを取得しています。今、同じコードで JForm を印刷したいのですが、これを行う方法がわかりません。ユーザーの詳細のいくつかのラベルとテキストフィールドを持つ JForm。これは、文字列「Hello World」を出力しているコードです。
public class PrintClass implements Printable, ActionListener {
public int display(Graphics g, PageFormat pf, int page) throws
                                                 PrinterException {
     if (page > 0) { /* We have only one page, and 'page' is zero-based */
        return NO_SUCH_PAGE;
    }
    /* User (0,0) is typically outside the imageable area, so we must
     * translate by the X and Y values in the PageFormat to avoid clipping
     */
   Graphics2D g2d = (Graphics2D)g;
   g2d.translate(pf.getImageableX(), pf.getImageableY());
    /* Now we perform our rendering */
   g.drawString("Hello World", 100, 100);
    /* tell the caller that this page is part of the printed document */
   return PAGE_EXISTS;
 }
文字列を渡す代わりに、JForm のコンストラクターを呼び出すのを手伝ってください。