File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Change background Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Change background" Watch "Change background" New topic
Author

Change background

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Hi,
I have an applet. In init method of an applet, I have set Background color of the an applet to white. But I run this applet throgh HTML file in browser, it will give gray color for 5 seconds and then it will change to white.
What may be reason?
Thanks in advance
Angela
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Angela,
Just off the top of my head, I believe the default color of an Applet is gray... or maybe it depends on how the browser is implementing the JVM??? Anyway, I have seen the behavior you have described and I don't think that there is any way around it. ( If the applet area is gray for a full 5 seconds though, you have a problem... Usually, it just flashes gray for a fraction of a second... either you have a very slow computer, a very slow connection, or a very big applet... )
HTH,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
Angela
The solution is to define init() to change the background color of the applet and the parent frame within which the applet is embedded. Normally the space that an applet uses on the screen is shown as a solid gray box while the applet is loading and initializing. This box tends to stand out on pages that use a background color other than gray. But there is a way around this problem. Applets always have a parent container in which they are embedded. Under both Netscape Navigator and Internet Explorer, this container is derived from the core Java class: java.awt.Container. So we need to use the methods inherited from java.awt.Component- setBackground() and repaint() to change the background color to the value of a bgcolor applet parameter. This makes the applet space stand out less than it does when it is gray.
For eg. do this:-
In the container HTML page set:-
<param name="bgcolor" value="#ffffff">
Define the public void init() of the applet as follows:-

This should solve the problem. Do let us know.
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428

Thanks to all
Rahul, I tried ur method. Atleast instead of 5 seconds, gray default background just comes for second, then it sets to white.
Is there solution for this?
Thanks,
Angela
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
No I don't think there is. The solution posted is the best workaround available.
However it is expected that in the newer browsers the frame will not default to gray- rather it will default to the background color of the page. So this problem will not occur then.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Change background