Как напечатать заголовок JTable в две строки? - PullRequest
1 голос
/ 14 марта 2009

Программа для печати JTabel и используемая функция

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"

);

Ничего не работает.

1 Ответ

0 голосов
/ 12 сентября 2011

попробуйте это.

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...