|
-
September 14th, 2000, 04:49 PM
#1
Printing
Just want to do a simple print screen from java application from menu item/toolbar button. Have following action listener which brings up the print dialog box, but does not print the screen, just a kernel error:
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
if (job.printDialog()) {
try {
job.print();
} catch (Exception prt) {
System.err.println(prt.getMessage());
}
}
}
-
February 1st, 2001, 11:00 PM
#2
Re: Printing
please try out this code
public void actionPerformed(ActionEvent e) {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(yourPanel.this);
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception prt) {
System.err.println(prt.getMessage());
}
}
}
And include a print method in your code:
public int print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex != 0) return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
g2.translate(pf.getImageableX(), pf.getImageableY());
paint(g2);
return PAGE_EXISTS;
}
neeraja
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|