Printing in Java

How can I send something to the printer?

Supose you have a window with a text in it and you want it to be printed.

thanks
cristian
crisoftAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
zia777Connect With a Mentor Commented:

   Design your GUI with any number of components in it. That is of no matter for us, when we intend to send the output to a printer. All you require is to include the following:

1. import java.awt.*;
2. Toolkit tk = Toolkit.getDefaultToolkit();
3. PrintJob pj = tk.getPrintJob(container object,"title",null);
4. Graphics g = pj.getGraphics(container object);
5. container Object.printAll(g);
6. g.dispose();
0
 
crisoftAuthor Commented:
I have a question:
I don´t know what is and how to use the container object. Can you give me a complete example using it?

thank you very much
cristian



1. import java.awt.*;
2. Toolkit tk = Toolkit.getDefaultToolkit();
3. PrintJob pj = tk.getPrintJob(container object,"title",null);
4. Graphics g = pj.getGraphics(container object);
5. container Object.printAll(g);
6. g.dispose();

0
All Courses

From novice to tech pro — start learning today.