How can I print a single JPanel's contents?

前端 未结 3 456
感动是毒
感动是毒 2020-11-29 03:28

I have a JPanel with two labels with pictures. I need to print these content of the JPanel. Please help me out. How can I print only this JPa

3条回答
  •  借酒劲吻你
    2020-11-29 04:07

    A simple way to do it would be implementing the Printable interface (in java.awt.print) and adding the specified print method (it works similar to paint—in here, you could specify what components you would want to draw onto the printed page). And when you want to actually print the contents of the panel, obtain a PrinterJob instance and call its setPrintable method, passing the object that implemented Printable.

    That's just a quick overview, though. I'd recommend taking a look at Sun's tutorial on printing for further information.

提交回复
热议问题