Article View: borland.public.jbuilder.java.swing
Article #8650I cannot print invisible Swing components
From: Mads Pultz
Date: Thu, 27 Jul 2000 00:00
Date: Thu, 27 Jul 2000 00:00
141 lines
5848 bytes
5848 bytes
This is a multi-part message in MIME format.
------=_NextPart_000_0008_01BFF7E7.D4F2C810
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi.=20
As the subject say, I cannot print invisible Swing components. I have a =
PrintPreview Swing object which handles my printing. If I choose to =
preview and then print everything works fine. If choose not to preview =
(I construct an instance of PrintPreview but call setVisible(false)) =
then nothing gets printed.=20
I can see from the printer pool that a print job is made but it is very =
small compared to the print job when PrintPreview is visible.=20
Here is some of the code I use to print with:=20
JComponent[] pages =3D makePages();=20
if (preview)=20
{=20
PrintPreview pp =3D new PrintPreview(this, pages, resources);=20
pp.setVisible(true);=20
}=20
else // no preview, just print=20
{=20
PrintPreview pp =3D new PrintPreview(this, pages, resources);=20
pp.setVisible(false);=20
PrintUtilities.printComponent(pp);=20
}
My PrintPreview class implements Pageable and Printable and my print =
method looks like this:=20
=20
public int print(Graphics g, PageFormat pageFormat, int pageIndex)=20
{=20
if (pageIndex >=3D getNumberOfPages())=20
return(NO_SUCH_PAGE);=20
else=20
{=20
Graphics2D g2d =3D (Graphics2D)g;=20
PrintUtilities.disableDoubleBuffering(this);=20
JComponent componentToBePrinted =3D pages[pageIndex];=20
componentToBePrinted.paint(g);=20
PrintUtilities.enableDoubleBuffering(this);=20
componentToBePrinted =3D null;=20
return(PAGE_EXISTS);=20
}=20
}=20
I use jdk 1.3 on Windows NT SP5.=20
Any help/comments would be appreciated. Please send your reply to =
mp@newcon.dk besides from posting it here.=20
Mads
------=_NextPart_000_0008_01BFF7E7.D4F2C810
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi. </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>As the subject say, I cannot print =
invisible Swing=20
components. I have a PrintPreview Swing object which handles my =
printing. If I=20
choose to preview and then print everything works fine. If choose not to =
preview=20
(I construct an instance of PrintPreview but call setVisible(false)) =
then=20
nothing gets printed. </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I can see from the printer pool that a =
print job is=20
made but it is very small compared to the print job when PrintPreview is =
visible. </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Here is some of the code I use to print =
with:=20
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>JComponent[] pages =3D =
makePages(); <BR>if=20
(preview) <BR>{ <BR> PrintPreview pp =3D new PrintPreview(this, =
pages,=20
resources); <BR> pp.setVisible(true); <BR>} <BR>else // no =
preview,=20
just print <BR>{ <BR> PrintPreview pp =3D new PrintPreview(this, =
pages,=20
resources); <BR> pp.setVisible(false); <BR> =20
PrintUtilities.printComponent(pp); <BR>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>My PrintPreview class implements =
Pageable and=20
Printable and my print method looks like this: </FONT></DIV>
<DIV><FONT face=3DArial size=3D2> <BR><FONT face=3D"Courier =
New">public int=20
print(Graphics g, PageFormat pageFormat, int pageIndex) <BR>{ <BR> =
if=20
(pageIndex >=3D getNumberOfPages()) <BR> =20
return(NO_SUCH_PAGE); <BR> else <BR> { =
<BR> =20
Graphics2D g2d =3D (Graphics2D)g; <BR> =20
PrintUtilities.disableDoubleBuffering(this); <BR> =
JComponent=20
componentToBePrinted =3D pages[pageIndex]; <BR> =20
componentToBePrinted.paint(g); <BR> =20
PrintUtilities.enableDoubleBuffering(this); <BR> =20
componentToBePrinted =3D null; <BR> =
return(PAGE_EXISTS);=20
<BR> } <BR>} </FONT></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I use jdk 1.3 on Windows NT SP5. =
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Any help/comments would be appreciated. =
Please send=20
your reply to <A href=3D"mailto:mp@newcon.dk">mp@newcon.dk</A> besides =
from=20
posting it here. </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Mads</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV></BODY></HTML>
------=_NextPart_000_0008_01BFF7E7.D4F2C810--
Technical Details
Message-ID:
<5IXf5.227$RT1.3460@news.get2net.dk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,1ee1caf3d04243a2,start X-Google-Attributes: gid111d45,public X-Google-Thread: 10fd6d,1ee1caf3d04243a2,start X-Google-Attributes: gid10fd6d,public From: "Mads Pultz" <mpultz@get2net.dk> Subject: I cannot print invisible Swing components Date: 2000/07/27 Message-ID: <5IXf5.227$RT1.3460@news.get2net.dk> X-Deja-AN: 651419667 X-Priority: 3 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0008_01BFF7E7.D4F2C810" X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Complaints-To: abuse@get2.net X-Trace: news.get2net.dk 964708225 195.82.214.100 (Thu, 27 Jul 2000 16:30:25 MET DST) Organization: get2net Internet Kunde X-MSMail-Priority: Normal MIME-Version: 1.0 NNTP-Posting-Date: Thu, 27 Jul 2000 16:30:25 MET DST Newsgroups: borland.public.jbuilder.java.swing,comp.lang.java.gui