开发者

Java Printing: How do i go about it?

I'm new to Graphics and Graphics2D in Java. Now i have a project where i have to print an Invoice to an A4 sized sheet.

I've been reading Sun's tutorial on printing.

I realized I'll need to first render the bill on a JFrame so i know what it'll look like.

Now, how do i go about setting the right sizes? I mean - if i design the bill on a JFrame (595, 842) - how will i map the coordinates (of all the shapes) correctly on to the print?

I'm basically clueless about where to begin. A lil'开发者_StackOverflow中文版 direction please?

Thanks. : )


If you put your invoice together using a JPanel (better than a JFrame, if you don't want the title bar, etc), you can implement Printable, and in its print method, you can use the Graphics object passed in to render your invoice. The Graphics object that the PrintJob passes in to the Printable can be used in your panel's paint method, but instead of it painting to the screen, it is painting to the printer. You will probably want to temporarily turn off double buffering.

With regard to how to design the invoice, you will want to pick out a LayoutManager for your JPanel and add a bunch of JLabels or you could use a JList with a custom renderer.


Have a look at this article...

http://www.java-tips.org/java-se-tips/java.awt.print/print-the-text-file-and-print-preview-them.html

I hope this will help you .. :)

Regards,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜