从Java JHotDraw中重写的getActions在上下文菜单中创建子菜单 [英] Creating a submenu in context menu from overridden getActions in Java JHotDraw
问题描述
我在基于Java的框架中重写 getActions
方法 JHotDraw
,一个托管的开源项目这里一>。方法 getActions
在 Drawingview $ c中的
图
上创建一个右键单击上下文菜单$ C>。我可以使用下面的代码正确添加addidtional上下文菜单选项。我需要知道如何在上下文菜单中添加子菜单。
I am overriding the getActions
method in the Java based framework JHotDraw
, an open source project hosted here. The method getActions
creates a right click context menu on Figure
in the Drawingview
. I can correctly add addidtional context menu options using the code below. I need to know how to add a sub menu to the context menu.
@Override
public Collection<Action> getActions(Point2D.Double p) {
Collection<Action> popupMenu = new ArrayList<Action>();
popupMenu.add(new AbstractAction("add Context Option 1") {
public void actionPerformed(ActionEvent event) {
preformThisMethod("params");
}
});
popupMenu.add(new AbstractAction("add Context Option 2") {
public void actionPerformed(ActionEvent event) {
preformThisMethod("params");
}
});
// How to add a sub menu to the context menu?
return popupMenu;
}
推荐答案
支持添加子菜单。
类 org.jhotdraw.gui.JPopupButton
extends JButton
提供整个框架中使用的弹出菜单。方法 add(javax.swing.JMenu子菜单)
可用于构造分层子菜单。例如, org.jhotdraw.samples.draw.DrawingPanel
将 Zoom
子菜单添加到<$中最右边的弹出菜单中c $ c> creationToolbar ,以及其他杂项编辑操作。 org.jhotdraw.draw.action.ButtonFactory
中的方法 createFontButton()
是另一个用于<$ c $的示例c> addFontButtonsTo()编辑器。
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.
相反,右键单击 org.jhotdraw.draw。 DefaultDrawingView
由 org.jhotdraw.draw.DelegationSelectionTool $ c中的
javax.swing.JPopupMenu
实例处理$ c>,如 org.jhotdraw.samples.mini.EditorSample
所示。特别是, AbstractAction
属性 Actions.SUBMENU_KEY
标识子菜单名称。设置 DEBUG = true
以查看效果。目前没有定义。
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.
这篇关于从Java JHotDraw中重写的getActions在上下文菜单中创建子菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!