Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Applet 2

Status
Not open for further replies.

Kulla

Technical User
Jul 30, 2002
16
0
0
US
I have this Navigation bar Java Applet, that does not print correctly from the browsers print command. Is there a workaround for this, for e.g. how do i disable printing of the applet on the webpage, or how do i replace the applet with a static image for printing purposes.
 
Hi Kulla,

I am not 100% sure about this and can't test it, but Applet has Container as an ancestor, which has a void print(Graphics) method that is used for printing Containers in Java. Try overriding this initially with an empty method to see if it works.

scrat
 
If you just want to remove the applet from the printed page all together you can use javascript in the page to define a print view by inserting the following style tags inside your html head section:
Code:
<STYLE MEDIA=print>
    APPLET {display: none}
</STYLE>
The easiest way to see this in action is to add it to a page and then do a print preview from the file menu.
Note: You may run into browser compatibility issues, I could not find a site that listed exactly wehich browsers supported this.

Using the same method, you could replace the applet with a screenshot by doing somthing similar to this:
Code:
<html>
<head>
<style media=&quot;print&quot;>
    applet {display: none}
    .screenshot {display: inline}
</style>
<style media=&quot;screen&quot;>
    applet {display: inline}
    .screenshot {display: none}
</style>
</head>
<body>
<applet .....>.....</applet>
<img src=&quot;myscreenshot.jpg&quot; class=&quot;screenshot&quot;>
</body>
</html>

Hope thats not to much stuff :p
Basically what this is going to do is hide the applet and show the picture when in print view, but show the applet and hide the image when in the browser.
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Thanks a lot Tarwn & scrat. Both your methods are great!

Except for the stylesheet method:It works perfectly fine in IE and NN7, but apparently not in NN4. Is there another way to define the style for NN4.

Thanks!
 
Sorry, NN4 handles styles very badly, as well as just about all the newer things you want to do. Fortunatly use of it is down to a very low percentage now.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top