Using JDK 1.1.8, how can I print a JTree component (in a JScrollPane), which is longer than one page?

Sandip Chitale

When a JTree component is inside a JScrollPane it still has its preferredSize. Thus you could do the following -

  1. Get a PrintJob.
  2. Get the dimensions of a printed page.
  3. Check how many pages (cells ? rows and columns) of pages will cover the rectangle of the JTree's size.
  4. In two nested loops - one for the rows and one for columns get the graphics from the PrintJob for each cell. Traslate the graphics to the right coordinates of the cell. Set the cliprect to the page size. Call the JTree's print method with that graphics.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact