Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: AWT
Expertise: Beginner
Mar 20, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

How to Fix Drop-down Box Conflict in Applet

I am unable to run an applet and use a drop-down box on the same page when using Netscape. The page has massive flickering and the applet will sometimes run. The applet runs just fine without the drop-down boxes.

Any suggestions?

I assume you're referring to the Choice widget, which creates a popup window to allow the user to select one of several possibilities. Netscape's implementation of java.awt.Choice is known to be extremely buggy, but there are work-arounds for some of the problems.

For instance, Netscape doesn't allow applets to set the default foreground and background colors of a Choice object, or set its Font and Font Style. While AWT components normally inherit these characteristics from their parent components, Netscape's implementation of Choice always uses the default settings. Appletviewer doesn't exhibit this problem.

Another problem with Choice objects in Netscape is that they don't redraw themselves properly. If your applet decides to set the choice itself (not in response to user input) the Choice object will not redraw itself. It'll go blank until the next redraw event is received by the widget.

The massive flickering you mention is probably due to the event handling for that object. You have to be careful which events you trap and handle.

In my experience, the following work-around seems to bypass most of the fatal problems:

To handle Choice events, use:

       public boolean handleEvent(Event e) {
               // To avoid flicker, make sure you're not handling
               // FOCUS events or other misc events
               if (e.target instanceof Choice && e.id == Event.ACTION_EVENT) {
                       int i = selChoice.getSelectedIndex();

                       // Do something with i ...

                       // You need this in order to force Netscape to
                       // draw the Choice widget again
                       return true;
               return false;

Similarly, whenever the applet wants to set the Choice to a particular item, make sure you call addNotify() right afterwards:
Note that none of the other redraw methods including repaint() and paint() do the trick with Netscape's implementation of Choice.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date