Re: printing three display components


Curtis Rueden wrote:
Hi Rakesh,

I don't know that much about printing in Java, but looking at
the DisplayImpl.getPrintable() method, it appears you could
construct a Printable object in whose print() method you create
a BufferedImage consisting of a synthesis of the three displays
(in whatever orientation you desire).  Use DisplayImpl.getImage()
to grab a BufferedImage with the contents of a VisAD Display.
See DisplayImpl.getPrintable() for an example of using the
Printable interface to send BufferedImages to the printer.

There could be an easier way, but that's really more of a Java
programming question, rather than a VisAD question.

Definitely a Java programming question. Nevertheless, I found code snippet lying around on my disk. Feel free to try it (I don't even now if it works; it might have worked, some time ago ;-) then let us know when you improved it.

NB: Follow Curtis' suggestions, and you'll also need to change

  final JPanel gp = this.getCentralPanel();

to match the panel where all your displays live.

  public Printable getPrintable()
    Printable printer=null;
    final JPanel gp = this.getCentralPanel();

    if (printer == null)
        new Printable() {
          public int print(Graphics g, PageFormat pf, int pi)
             throws PrinterException
            if (pi >= 1)
               return Printable.NO_SUCH_PAGE;

                                        // or: LANDSCAPE

            //JPanel gp =  getcentralPanel();
Image image = (Image) gp.createImage(gp.getWidth () ,gp.getHeight());
             Graphics gg = image.getGraphics();
             BufferedImage bufImage = (BufferedImage)image;

            //BufferedImage image = DisplayImpl.this.getImage();
                (int) pf.getImageableX(),
                (int) pf.getImageableY(),
            return Printable.PAGE_EXISTS;
    return printer;



  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: