Printing from Applet

U

umerkle

Hello,


i'm trying to print from my applet under Lotus Notes. There is a
JavaScript function that calls
the applet's print-method which looks like that:

public void printApplet () {
//Panel printPanel = new Panel();
Panel printTitlePanel = new Panel();
Panel printTitle = new Panel();

Color oldColor;
Color oldForeground;
Font oldFont;
Frame frame = new Frame(TransStrings.printDialog);

Properties printprefs = new Properties();
Toolkit toolkit = this.getToolkit();
try{
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPrintJobAccess();
security.checkPropertiesAccess();
security.checkTopLevelWindow(frame);
}
}catch(SecurityException e){
e.printStackTrace();
return;
}

PrintJob job = null;
try{
job = toolkit.getPrintJob(frame, TransStrings.printDialog,
printprefs);
}catch(Exception e){
e.printStackTrace();
}
if (job == null)
return;
printTitlePanel.setBackground(Color.white);
oldColor = this.getBackground();
this.setBackground(Color.white);
oldForeground = this.getForeground();
this.setForeground(Color.black);
oldFont = this.getFont();
this.setFont(new Font("Helvetica", Font.PLAIN,10));
Graphics g = job.getGraphics();
if (g != null) {
g.translate(25, 25);
Dimension size = this.getSize();
PlanerOptions.planer.add(printTitlePanel,"PRINT");
PlanerOptions.planer.doLayout();
PlanerOptions.planer.repaint();
if (PlanerOptions.ONEUSERMODE) {
g.setClip(0, 0, PlanerOptions.rowDescrWidth +
(32*PlanerOptions.xDist),
size.height);
}
else {
g.setClip(0, 0, size.width, size.height);
}

if(PlanerOptions.bShowMessages)
System.out.println("--> Druck!");

this.printAll(g);
PlanerOptions.planer.remove(printTitlePanel);
PlanerOptions.planer.doLayout();
PlanerOptions.planer.repaint();
g.dispose();
}
job.end();

this.setBackground(oldColor);
this.setForeground(oldForeground);
this.setFont(oldFont);
}



under R5 with JDK 1.1 everything is OK, but under R6 with JDK 1.3.x
the system hangs while calling job = toolkit.getPrintJob(frame,
TransStrings.printDialog, printprefs)

Are there any differences in this function between JDK 1.1 and 1.3 ? What
is wrong with my code ?



Uwe
 
I

Ike

Uwe,

Below is simple code that does a beautiful job printing from an Applet under
1.3.x -- to paint the contents of a Panel. Specifically, I am using it for
Swing JPanels. Perhaps you may wish to copy your specifics into it. -Ike

public void doPrint(){
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pageFormat = job.defaultPage();
job.setPrintable( this , pageFormat );
if(job.printDialog()){
try{
job.print();
}catch(Exception e){
e.printStackTrace();
}
}
}
public int print(Graphics g, PageFormat pf, int pageIndex) throws
PrinterException{
Graphics2D g2=(Graphics2D)g;
g2.translate( (int)pf.getImageableX() ,(int)pf.getImageableY() );
boolean db=isDoubleBuffered();
//turn off double buffering in swing components before you print or
it looks like alt-printscrn
setDoubleBuffered(false);
paint( g2 );
setDoubleBuffered(db);
if( pageIndex > 0 )
return Printable.NO_SUCH_PAGE;
else
return Printable.PAGE_EXISTS;
}
 
U

umerkle

Hi Ike,

does this work under 1.1 too?

My applet has to work under 1.1 and 1.3 !



Uwe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top