🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #8650

I cannot print invisible Swing components

#8650
From: Mads Pultz
Date: Thu, 27 Jul 2000 00:00
141 lines
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>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is some of the code I use to print =
with:=20
</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>JComponent[] pages =3D =
makePages(); <BR>if=20
(preview) <BR>{ <BR>&nbsp; PrintPreview pp =3D new PrintPreview(this, =
pages,=20
resources); <BR>&nbsp; pp.setVisible(true); <BR>} <BR>else&nbsp; // no =
preview,=20
just print <BR>{ <BR>&nbsp; PrintPreview pp =3D new PrintPreview(this, =
pages,=20
resources); <BR>&nbsp; pp.setVisible(false); <BR>&nbsp;=20
PrintUtilities.printComponent(pp); <BR>}</FONT></DIV>
<DIV>&nbsp;</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>&nbsp;<BR><FONT face=3D"Courier =
New">public int=20
print(Graphics g, PageFormat pageFormat, int pageIndex) <BR>{ <BR>&nbsp; =
if=20
(pageIndex &gt;=3D getNumberOfPages()) <BR>&nbsp;&nbsp;&nbsp;=20
return(NO_SUCH_PAGE); <BR>&nbsp; else <BR>&nbsp; { =
<BR>&nbsp;&nbsp;&nbsp;=20
Graphics2D g2d =3D (Graphics2D)g; <BR>&nbsp;&nbsp;&nbsp;=20
PrintUtilities.disableDoubleBuffering(this); <BR>&nbsp;&nbsp;&nbsp; =
JComponent=20
componentToBePrinted =3D pages[pageIndex]; <BR>&nbsp;&nbsp;&nbsp;=20
componentToBePrinted.paint(g); <BR>&nbsp;&nbsp;&nbsp;=20
PrintUtilities.enableDoubleBuffering(this); <BR>&nbsp;&nbsp;&nbsp;=20
componentToBePrinted =3D null; <BR>&nbsp;&nbsp;&nbsp; =
return(PAGE_EXISTS);=20
<BR>&nbsp; } <BR>} </FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I use jdk 1.3 on Windows NT SP5. =
</FONT></DIV>
<DIV>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Mads</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</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-mail

Show 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