开发者

Print multiple portions of java JTable to single page

开发者 https://www.devze.com 2023-03-04 02:26 出处:网络
In an application I am currently developing, I have a JTable that get开发者_C百科s data from a table model (i have subclassed the DefaultTableModel). When I want to print the JTable I use a modified v

In an application I am currently developing, I have a JTable that get开发者_C百科s data from a table model (i have subclassed the DefaultTableModel). When I want to print the JTable I use a modified version of a class that I found online and manage to print it exactly as it appears on the application (using my custom cell renderer).

I wonder though, if anyone can point me on how to print multiple portions of the table in the same page. My table has 3 columns and hundreds of rows. Currently I am printing on each page the three columns and approx. 30 rows. I would like to print to each page two portions, i.e. two pages in one, so that each page has a left part with 3 columns and 30 rows and the right side the 3 columns with the next 30 rows.

Thanx in advance!

Update: Instead of printing:

Page 1: 

Col1 | Col2 | Col3
val1 | val2 | val3

Page 2:

Col1 | Col2 | Col3
val4 | val5 | val6

I wish to print:

Page 1:

Col1 | Col2 | Col3          Col1 | Col2 | Col3
val1 | val2 | val3          val4 | val5 | val6

Thanx!!!


please check this tutorial Printing, (there is way) how to create custom formated previue just for printOut


I while back I was looking for a ready API myself. I found nothing that would do what I want for free.

Thus I think you will have to handle it yourself. You need to make appropriate calculations yourself.

For example:

  • you need to know how many pages it will take under normal conditions.
  • then you evaluate how much space you need for a single page on the printout page.
  • then you move translate your graphics, scaling accordingly so it will fit right.

I would suggest you try first with only a single dimension, e.g. scale only height so it fits one under another, do not worry about width scaling for the first time.

Hope it is any help to you. Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号