Z-Order Bug Demonstration

Platforms Affected

For Frames (Independant Windows), Netscape 3 & 4 on Windows uses different z-order versus IE on Windows & Netscape on Mac, UNIX.

For Applet Panels, Windows Internet Explorer's Java VM uses a different z-order versus everything else.

Details On The Z-Order Bug

In the Java AWT, you can code your look and feel so that some components overlap other components. While you would not delibrately code a listbox to cover part of another listbox, it is entirely conceivable that you may code a drop-down box which does NOT cover any other element until the user clicks the drop down box and activates its list of components for drawing.

Z-Order is basically the 3D depth order in which components get drawn on the panel.

Netscape for Windows draws the components in the order in which they were added to the layout manager. Thus, the last component added to the layout manager will end up drawing on top of previous components if they overlap.

Other JVMs, on the other hand, have the reverse z-order! Components that are added after other components are actually drawn first. Thus, it becomes necessary to add code which checks for this if you need to use drop down boxes and do not want it to be blocked by other components on these other JVMs.

Note, the Java choice() component is an AWT-Peer class which is implemented using the corresponding native operating system widget and therefore tends to know that it needs to overlap all other controls regardless of z-order. However, a user programmed combobox from a commercial class library that uses a straight canvas to draw the drop-down effect will run into this problem.

The code demos at the bottom of this page demonstrates this bug. The first two three demos focus around the z-ordering problem using Frames or independant windows in Java.

The first "bug" demo has the third green label on top of the second red label in Netscape for Windows and the reverse for all other platforms. The second bug demo reverses the add() order and shows how the z-order does really matter for display.

The subsequence bug demos focus on the z-ordering problem on Applet panels. Here the problem is Internet Explorer on Windows versus everything else.

Z-Order Workaround

Finally, the third applet for each section (Frame vs Applet Panel) demonstrates how to use conditional logic to workaround this z-order bug. In this applet, all browsers should see the third green component overlapping the previous red component. The components are added in the appropriate order to the layout manager depending on the OS and Browser type.

References

Developer.com's article on "Write Once, Run Anywhere?" by Jason W. Purdy

Applet Demonstrating Z-Order Bug

View The Source To ZOrderBug.java
View The Source To ZOrderBugFrame.java

Applet Demonstrating Z-Order Bug In Reverse

View The Source To ZOrderReverseBug.java
View The Source To ZOrderReverseBugFrame.java

Applet With Z-Order Bug Workaround

View The Source To ZOrderFix.java
View The Source To ZOrderFixFrame.java

Applet Demonstrating Z-Order Applet Panel Bug

View The Source To ZOrderPanelBug.java

Applet Demonstrating Z-Order Applet Panel Bug In Reverse

View The Source To ZOrderPanelReverseBug.java

Applet With Applet Panel Z-Order Bug Workaround

View The Source To ZOrderPanelFix.java

Gunther Birznieks