The Network  
Network Search Sites Services ITcareers
Advertisement: Support JavaWorld, click here!


Mail this Article
Printer-Friendly Version

put phrases in quotes

Topical index
Net News Central
Developer Tools Guide
Component Guide
Book Catalog
Writers Guidelines
Privacy Policy


Java Tip 12: How to make cascading menus in Java

How to make cascading menus in Java

This week we show how to make multiple levels of cascading menus. (200 words)
By John D. Mitchell

Java Tips

For a comprehensive list of Java Tips published in JavaWorld, see the Java Tips Index

Do you have a tip that would benefit JavaWorld's readers? We would like to pass it on! Submit your tip to

The plain little Java window that has popped up to annoy you exists for sole purpose of showing you how Cascading Menus work. These are also known as Pull-Right Menus since they open up to the right of their parent.

Go click on the File menu and then on its various menu items and their children to see how deep the menu nesting goes.

Here is the code for the CascadeApplet applet. It's pretty basic in that all it does is create and then display our Frame.

Here is the code for the CascadeMenus subclass of Frame. Basically, it just creates a new Menu rather than another MenuItem whenever it wants to create a cascading menu.

Now that you know how to make cascading menus, please use them judiciously. As in my example, it is easy to make things more confusing by using Cascading menus. Also keep in mind that a number of us mouse-jockeys are spastic and therefore have a hard time navigating complicated menu hierarchies with these new-fangled mice.


JavaWorld also features a Java Questions & Answers column! Send your Java language questions to now. We would also like to pass on your Java Tips to the rest of the Java world. Start writing up your coolest tips and tricks now so that you can send them in -- and be eligible for JavaWorld's "Java Tip of the Week" contest. If your Java tip is chosen as JavaWorld's "Java Tip of the Week," you'll be awarded a prized JavaWorld T-shirt and 10,080 minutes of fame and prestige. Send your Java tips and tricks to

About the author
Subsisting on caffeine, sugar, and too little sleep, John D. Mitchell has been consulting for most of the last nine years, and developed PDA software in OO assembly language at Geoworks. He funds his Java addiction by writing compilers, Tcl/Tk, C++, and Java systems. He co-authored the hot new Java book Making Sense of Java and is currently developing a Java compiler.

Tell us what you
thought of this story

-Very worth reading
-Worth reading
-Not worth reading

-Too long
-Just right
-Too short

-Too technical
-Just right
-Not technical enough



Company Name:


Home | Mail this Story | Printer-Friendly Version

Advertisement: Support JavaWorld, click here!

(c) Copyright, Inc., an IDG Communications company

Technical difficulties:
Last modified: Wednesday, February 21, 2001