Creating a submenu in context menu from overridden getActions in Java JHotDraw

Adding submenus is supported.

The class org.jhotdraw.gui.JPopupButton extends JButton to provide the popup menus used throughout the framework. The method add(javax.swing.JMenu submenu) may be used to construct hierarchical submenus. For example, org.jhotdraw.samples.draw.DrawingPanel adds a Zoom submenu to the rightmost popup menu in creationToolbar, along with other miscellaneous editing actions. The method createFontButton() in org.jhotdraw.draw.action.ButtonFactory is another example used to addFontButtonsTo() the editor.

In contrast, right-clicking on the org.jhotdraw.draw.DefaultDrawingView is handled by an instance of javax.swing.JPopupMenu in org.jhotdraw.draw.DelegationSelectionTool, as shown in org.jhotdraw.samples.mini.EditorSample. In particular, the AbstractAction property Actions.SUBMENU_KEY identifies a submenu name. Set DEBUG = true to see the effect. None are presently defined.

Leave a Comment