Java Reference
In-Depth Information
frame.setJMenuBar(menuBar);
frame.setSize(350, 250);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Menu Class Hierarchy
Now that you've seen an example of how to create the cascading menus for an application, you
should have an idea of what's involved in using the Swing menu components. To help clarify,
Figure 6-2 illustrates how all the Swing menu components are interrelated.
Figure 6-2. Swing menu class hierarchy
The most important concept illustrated in Figure 6-2 is that all the Swing menu elements,
as subclasses of JComponent , are AWT components in their own right. You can place JMenuItem ,
JMenu , and JMenuBar components anywhere that AWT components can go, not just on a frame.
In addition, because JMenuItem inherits from AbstractButton , JMenuItem and its subclasses
inherit support for various icons and for HTML text labels, as described in Chapter 5.
 
Search WWH ::




Custom Search