🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19106

Re: Printing: I get Print Dialog, but nothing prints!

#19106
From: John Niesz
Date: Sat, 14 Mar 1998 00:00
61 lines
3034 bytes
The reason nothing prints (in JDK 1.1.2, the Borland version) is because
you haven't shown your frame yet.  It must be visible in order for the
print to work right.  Also, on JDK 1.1.2, the page size is the only
printing bug I've found, it makes it too small.  One article in this
newsgroup said it was 75%, though I've never done the math, but if you were
to include this code:

setSize(myprintjob.getPageDimension().width*1.33333,
myprintjob.getPageDimension().height*1.33333);

before printing, after showing, and removing the pack() call that Borland
loves to put in, it should print at the right size, providing it really
returns 75% of the actual size.  Your code would then be:

Frame myframe=new Frame();
myframe.show();
myframe.setSize(myprintjob.getPageDimension().width*1.33333,
myprintjob.getPageDimension().height*1.33333);
PrintJob myprintjob=Toolkit.getDefaultToolkit().getPrintJob(myframe,"AWT
Print",new Properties());
Graphics mygraphics = myprintjob.getGraphics();
myframe.printAll(mygraphics);
mygraphics.dispose();
myprintjob.end();

This code would print the frame and all of it's subcomponents, although in
my experience, the bottom of the frame is left out, due to yet another bug
in the Sun implementation.

Of course, you would have to check to make sure the program is being run on
Java 1.1.2, which means some other call (I'm sure you can find this in the
documentation, probably part of the System class.).  I haven't tried
printAll() on any other versions, but I know that JDK 1.1.5 also has page
size problems, the height it returns is slightly too much.  Good luck!

John


Alex Humphreys wrote:

> I'm trying to print a string, but for some reason I get Windows' Print
> Dialog, but then Nothing Prints.  I've tried to follow the instructions
> I've found in this newsgroup, and nothing seems to help.
>
> I have the following in my jbinit of a Frame I just created.  the print
> dialog comes after the first line, so the Graphics calls don't seem to
> do anything.
>
>     PrintJob myJob =
> Toolkit.getDefaultToolkit().getPrintJob(this,"AlexH",new Properties());
>     Graphics myGraphics = myJob.getGraphics();
>     this.printAll(myGraphics);
>     myGraphics.dispose();
>     myJob.end();
>
> (incidentally, what should be printed if I do this?  an image of the
> Frame?  A string that I can specify?)
>
> Thanks.
> --Alex
Technical Details
Message-ID: <350B5D77.FCC1FD7F@worldnet.att.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <34FDB70E.5A5784F6@sema4.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,56b3af2cddf188a7
X-Google-Attributes: gidf74b3,public
From: John Niesz <sunrunner15@worldnet.att.net>
Subject: Re: Printing:  I get Print Dialog, but nothing prints!
Date: 1998/03/14
Message-ID: <350B5D77.FCC1FD7F@worldnet.att.net>
X-Deja-AN: 334172503
Content-Transfer-Encoding: 7bit
References: <34FDB70E.5A5784F6@sema4.com>
To: Alex Humphreys <ahumphreys@sema4.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language