2009-03-14 8 views
1

プログラムはJTabelを印刷することであり、使用される関数はJTableヘッダーを2行で印刷するにはどうすればよいですか?

JTabel jt=new JTable(); 
MessageFormat headerFormat= new MessageFormat("My World Tomorrow"); 
MessageFormat footerFormat = new MessageFormat("Page {0}"); 

jt.Print(JTabel.Format,headerFormat,footerFormat); 

クエリである:

My World 
Tomorrow 

疲れ以下の溶液で二行のヘッダを印刷する方法:

new MessageFormat("My world \n Tomorrow"); 
new MessageFormat("My world \r\n Tomorrow"); 
new MessageFormat("My world" System.getProperty("line.separator")+"Tomorrow" 

);

何も機能しません。

+0

StackOverflowのErulsへようこそ掲載します。コードを投稿するときは、4つ分のスペースをインデントするか、コードを強調表示し、質問を編集するときにコードの書式設定ボタンを押します。読むのがはるかに簡単になり、答えを得る機会が増えます。 –

+0

こんにちは、ありがとうPaul。 –

+0

バックスラッシュ(\)を1つ試しましたか? –

答えて

-1

これを試してください。

PrinterJob job = PrinterJob.getPrinterJob(); 
MessageFormat[] header = new MessageFormat[3]; 
header[0] = new MessageFormat(""); 
header[1] = new MessageFormat("line 1"); 
header[2] = new MessageFormat("line 2"); 

MessageFormat[] footer = new MessageFormat[2]; 
footer[0] = new MessageFormat("footer 1"); 
footer[1] = new MessageFormat("footer 2"); 
job.setPrintable(new MyTablePrintable(tblmunim, PrintMode.FIT_WIDTH, header, footer)); 

if (job.printDialog()) 
    try { 
    System.out.println("Calling PrintJob.print()"); 
    job.print(); 
    System.out.println("End PrintJob.print()"); 
    } 
    catch (PrinterException pe) { 
    System.out.println("Error printing: " + pe); 
    } 

は、もともとここhttp://sandeepsharma11.blogspot.com/2010/12/java-how-to-print-table-with-multi-line.html

+0

これは、MyTablePrintableの実装がなければ役に立たず、マジックが起こるはずです。 – ths

+0

こんにちはThsそれは長い時間されていますスイングで動作していないが、あなたはこれを試すことができます。 1)TablePrintableのコードを取得し、自分のクラス "MyTablePrintable"にコピーします。 2)必要に応じてコンストラクタを変更します。 – sandy

関連する問題