SmartJReport - (JTreeTable - Print, PDF, TIFF, PostScript, PNG, BMP, GIF, JPG, JPEG and more)

Visit our website and learn more about SmartJReport that supports all of your Java report, print, PDF and conversion requirements.

Print, PDF, Preview JTreeTable - The Demo

This demo sample shows how to Print, PDF or simply preview an existing JTreeTable. You can "silent print your JTreeTable" using the JavaTablePrinter methods which you can learn looking the at the PrintTreeTableDemo.java sample.

In the downloaded archive you will see some sample batch programs (e.g. PrintTreeTableDemo.bat, PrintTreeTableDemo.sh and more). For each batch file there is a corresponding JAVA sample program made available as part of the downloaded archive. Run the PrintTreeTableDemo.bat (Windows) or PrintTreeTableDemo.sh (Unix/Linux) for example to see the following window with a JTreeTable and few buttons to "Print", "PDF" and "Preview" the JTreeTable.

The Demo JTreeTable

Print JTreeTable

You can either "Silent print your JTreeTable" or provide UI controls such as menus and buttons as demonstrated in this sample program and print, PDF, preview and more. When printing or previewing optionally you can choose to show a print dialog or a page dialog depending on the parameters values in the JavaTablePrinter.print() method. In this sample we show a "print dialog" to let user select a printer, paper, orientation, copies, fit to printable area and others as seen in the print dialog next.

This is how typical print dialog look like with various printing parameters. There is the "Fit to Printable Area" option used to fit output within the paper width.

Here is how the print preview window looks like when previewed instead of printing it to a printer directly.

Print JTreeTable with Fit to Page Width

JavaTablePrinter class responsible for generating a report from JTreeTable lets you set a FIT flag so the output may be fit to the page width. It is better to always set the flag so it can fit to page width applying compression if necessary. Available fit options are AbstractPrinter.PAGE_SCALING_NONE (no fit) and AbstractPrinter.PAGE_SCALING_FIT_TO_PRINTABLE_AREA (fit to page width) applied using setPageScaling(int) method. In the print dialog there is a check box "Fit to Printable Area" is equivalent to the above. Here is how the preview page looks like when you apply "Fit" to page width.

PDF JTreeTable

The report engine can let you convert the JTreeTable report pages to a PDF document. You can convert JTreeTable to PDF completely silently by getting a Pageable from calling JavaTablePrinter.Pageable() and then passing the Pageable to the ConversionFactory.saveAsPdf(Pageable) method. Following are some PDFs created out of sample Swing JTreeTable component.

  • JTreeTable to PDF (No Fit)
  • JTreeTable to PDF (Fit to Page Width)
  • Preview JTreeTable

    Report lets you preview JTreeTable report pages in a preview window before printing or conversion to other data formats. JavaTablePrinter class has few preview() methods to call for showing the preview window. This demo chooses to show a paper selection dialog before showing the preview window. It is also important to remember that the preview window has options for the end user to Print, PDF and conversion to images. Preview window also lets you zoom in and out in order to control number of pages to output.

    Select paper size and orientation from this "Paper Selection" window.

    JTreeTable to PNG, BMP, GIF and JPEG/JPG

    Look at the resized image creation samples such as Report2ResizedPNG.java, Report2ResizedBMP.java, Report2ResizedGIF.java, Report2ResizedJPEG.java and other conversion samples in the downloaded archive.

    There are ways to convert JTreeTable report pages to many different image formats such as PNG, BMP, GIF and JPEG/JPG. If you want to convert JTreeTable to images silently we suggest you to get a Pageable (each page of which is an AbstractPage) form the JavaTablePrinter class and then pass the Pageable to the ConversionFactory.saveAsBMP(AbstractPage) (BMP), ConversionFactory.saveAsPNG(AbstractPage) (PNG), ConversionFactory.saveAsGIF(AbstractPage) (GIF), ConversionFactory.saveAsJPEG(AbstractPage) (JPEG), ConversionFactory.saveAsJPG(AbstractPage) (JPG) to convert to images. Conversion APIs provide the option to pass a resize factor so the output images size can be enlarged or shrinked.

    This demo sample lets you preview the JTreeTable report pages. From the preview window you can convert one or more of the JTreeTable report pages to images.

    JTreeTable to TIFF

    This is similar to the above. Get the Pageable (convert to AbstractPage[] array) and call ConversionFactory.saveAsTIFF(AbstractPage[]) to produce the TIFF report.

    Also look at Report2ResizedTiffDemo.java demo sample in the downloaded archive.

    JTreeTable to Post Script

    Get the Pageable and create an array of AbstractPage[] then call ConversionFactory.saveAsPostScript(AbstractPage[]) to produce the Post Script output of your JTreeTable report.

    Also look at Report2PostScriptDemo.java demo sample in the downloaded archive.