hi everybody, cud neone here pls help me out in printing a page in Java. I have a page designed in swings which contains mainly labels and textareas. And i need to print this page in java with a click of a button. Could nebody arnd please help me out in this matter as it is very urgent and important. I will be really grateful to all the masters here.

<<snipped>>
Thanks and kind regards,
Rahul Gupta.

PrintService[] services3 = PrintServiceLookup.lookupPrintServices([B]null[/B], [B]null[/B]);
AttributeSet aset3 = [B]new[/B] HashAttributeSet();
aset3.add([B]new[/B] PrinterName("my printer name", [B]null[/B]));
aset3.add(MediaTray.BOTTOM);
services3 = PrintServiceLookup.lookupPrintServices([B]null[/B], aset3);
PrinterJob pjob = PrinterJob.getPrinterJob();

try this . it will work

thanks for the prompt reply. but how can I implement this with my JFrame page.???

PrintService[] services3 = PrintServiceLookup.lookupPrintServices([B]null[/B], [B]null[/B]);
AttributeSet aset3 = [B]new[/B] HashAttributeSet();
aset3.add([B]new[/B] PrinterName("my printer name", [B]null[/B]));
aset3.add(MediaTray.BOTTOM);
services3 = PrintServiceLookup.lookupPrintServices([B]null[/B], aset3);
PrinterJob pjob = PrinterJob.getPrinterJob();

try this . it will work

You want to take printout of which thing ...?
You can add print job listener to your printjob and then you can implement your own set of actions.
Or in actionPerformed of button event you can create a printjob and add it for printing.

something like this

services3.createPrintJob();
.
.
.
pjob.print();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.