-------------------------------------------------------------------------- Printing Images in Java 1.1: --------------------------------------------------------------------------- Printing in Java 1.1 is EASY! Java 1.1 includes some classes and methods that make printing an easy task. The following text is a quick overview of the process. First, create a print job : PrintJob job = Toolkit.getDefaultToolkit().getPrintJob( my_frame,"Job Title",print_properties); //check if user didn't cancel if(job == null) return; This will pop-up a window prompting the user for information about the print job, such as printer name. This information is stored in print_properties. This information can be used to save the default user preferences, if you don't care to save, just pass a null value. The next step is to get a graphics object for the page, you can also get the page size: Graphics page = job.getGraphics(); Dimension pagesize = job.getPageDimension(); Now you are ready to print as you would paint anything with a graphics object. ATTENTION: this graphics object is not initiallized at all! You MUST set a color before you draw, you should also set the font if you want to write anything, for example: page.setFont(new Font("Dialog",Font.BOLD,20)); page.setColor(Color.black); The system will not check if you draw outside of the page bounds, so include a command to clip the drawing to the page size: page.setClip(0,0,pagesize.width,pagesize.height); Now, you a really ready to print anything. Once you have finished printing that page, you should send it to the printer : page.dispose(); You can print another page by getting another graphics object and following the same steps. Finally, when you have sent all pages to the printer you should end the print job: job.end(); THAT IS IT! Printing components: java.awt.Component (super class of Frame, Button, etc) defines a method to print the component: public void print(Graphics g) Where g should be the graphics object for the printer page. The default implementation of this method is to pass the Graphics g object to the Component's paint(Graphics g) method. Thus, the component will be printed in the same way as it is display on screen. If you want it to be printed differently from the way it is displayed, just override the print(Graphics g) method. To print a hierarchy of Components, call the printAll(Graphics g) method on the root Component of the hierarchy.