We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Printing Papplet from Swing container
Page Index Toggle Pages: 1
Printing Papplet from Swing container (Read 684 times)
Printing Papplet from Swing container
Jul 19th, 2006, 4:15pm
 
Hello,
I have a chart Papplet inside a JPanel, call it ParentPanel. The ParentPanel also has a couple of other legend Jpanels inside it.

I want to fire a print command to print both the Papplet chart and the legend JPanels.

so in ParentPanel i do something like
ParentPanel

     Dimension size = ParentPanel.getSize();
      BufferedImage myImage =
        new BufferedImage(size.width,size.height,
        BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = myImage.createGraphics();
((PApplet)chart).paint(g2);
legendPanel.paint(g2);

This makes an image but, the legendPanel is painted on the top of the page instaed of after the PApplet.

If to try to do a parentPanel.paint(g2) the PApplet chart is not printed at all.

How do i print an JPanel with Papplet and other JPanels within it, maintianing their relative poistions?

Thank you
Sameer
Re: Printing Papplet from Swing container
Reply #1 - Aug 19th, 2006, 10:31pm
 
In your Swing app's init code:
   
MyPApplet mpa = new MyPApplet();
mpa.init();
add(mpa);
pack();
// this last two lines must be in the class that extends some kind of  container, like a JFrame or JPanel
// nothing will happen until you call init() on your PApplet

Cheers!
Dr.E
Page Index Toggle Pages: 1