devxlogo

How to Fix Drop-down Box Conflict in Applet

How to Fix Drop-down Box Conflict in Applet

Question:
I am unable to run an applet and use a drop-downbox on the same page when using Netscape. The page hasmassive flickering and the applet will sometimes run. Theapplet runs just fine without the drop-down boxes.

Any suggestions?

Answer:
I assume you’re referring to the Choice widget, which createsa popup window to allow the user to select one of several possibilities.Netscape’s implementation of java.awt.Choice is known to beextremely buggy, but there are work-arounds for some of theproblems.

For instance, Netscape doesn’t allow applets to set the defaultforeground and background colors of a Choice object, or set itsFont and Font Style. While AWT components normally inherit thesecharacteristics from their parent components, Netscape’s implementationof Choice always uses the default settings. Appletviewer doesn’texhibit this problem.

Another problem with Choice objects in Netscape is that they don’tredraw themselves properly. If your applet decides to set thechoice itself (not in response to user input) the Choiceobject will not redraw itself. It’ll go blank until the nextredraw event is received by the widget.

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

In my experience, the following work-around seems to bypassmost 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                       selChoice.addNotify();                       return true;               }               return false;       }
Similarly, whenever the applet wants to set the Choice to aparticular item, make sure you call addNotify() rightafterwards:
       selChoice.select(i);       selChoice.addNotify();
Note that none of the other redraw methods including repaint() andpaint() do the trick with Netscape’s implementation ofChoice.

See also  The Art of AI-Generated Meeting Minutes
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist