Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Java Tip 12: How to make cascading menus in Java

How to make cascading menus in Java

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
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.

Enjoy!

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.
  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources