Example: Printing a Small Crosstab and a Graph on the Same Page

This example shows how to print a single logical page of a small crosstab and a graph on the same physical page. This example assumes that you have a crosstab named smallCrosstab, which has few enough rows and columns to fit on half a physical page. This example also assumes that you have a graph named myGraph.


CrosstabPrinter ctPrinter = new CrosstabPrinter(smallCrosstab); GraphPrinter grPrinter = new GraphPrinter(myGraph); Frame frame = oracle.bali.ewt.util.WindowUtils.parentFrame(smallCrosstab); PrintJob job = (java.awt.Toolkit.getDefaultToolkit()).getPrintJob(frame, "Print", null); // find the size of the paper Dimension pageDim = job.getPageDimension(); // divide in half for each view, allowing for a 1/4-inch gutter between views Dimension crosstabDim = new Dimension(pageDim.width, (pageDim.height / 2) - 9); Dimension graphDim = new Dimension(crosstabDim); // tell the printers how much space is available for the views ctPrinter.setViewDimension(crosstabDim); grPrinter.setViewDimension(graphDim); // set properties on the printers here, before calling startPrint ctPrinter.setRangeType(ViewPrinter.CURRENT_LOGICAL_PAGE); grPrinter.setRangeType(ViewPrinter.CURRENT_LOGICAL_PAGE); // print the crosstab if (ctPrinter.startPrint()) { Graphics g = job.getGraphics(); //go to the first physical page, even though there is only one if (ctPrinter.prepareFirstPage(g)) ctPrinter.renderPage(g); ctPrinter.endPrint(); //reuse the Graphics object, adding a 1/4" gutter between views g.translate(0, (crosstabDim.height + 18)); } //print the graph to the print job if (grPrinter.startPrint()) { if (grPrinter.prepareFirstPage(g)) grPrinter.renderPage(g); grPrinter.endPrint(); g.dispose(); } //end the print job job.end();