2009-03-14 2 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

에 오신 것을 환영합니다 여기에 게시. 코드를 게시 할 때 4 칸만큼 들여 쓰거나 코드를 강조 표시하고 질문을 편집 할 때 코드 서식 버튼을 누릅니다. 읽는 것이 훨씬 쉬워지고 답을 얻을 확률이 높아집니다. –

+0

안녕하세요 폴. –

+0

하나의 백 슬래시 (\)를 사용해 보셨습니까? –

답변

-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); 
    } 

는 원래 StackOverflow의 Eruls에 http://sandeepsharma11.blogspot.com/2010/12/java-how-to-print-table-with-multi-line.html

+0

이것은 MyTablePrintable 구현이 없으면 쓸모가 없습니다. – ths

+0

안녕하세요, 오랜 시간이었습니다. 스윙에 대해 작업하지 않고 있지만 시도해 볼 수는 있습니다. 1) TablePrintable의 코드를 가져 와서 자신의 클래스 "MyTablePrintable"에 복사합니다. 2) 필요한 경우 생성자를 수정하십시오. – sandy

관련 문제