[英]Swing - Menu With Open Windows
For user convenience, and after reading user interface guidelines, I would like a JMenu with Items as open Windows in my program, eg different (non-modal) dialogs/frames. 为了用户方便,在阅读了用户界面指南之后,我希望在程序中使用带有菜单项的JMenu作为打开的Windows,例如,不同的(非模式)对话框/框架。
The menu lists the windows, and focuses them when clicked (Mentioned in Mac Human Interface Guidelines). 该菜单列出了窗口,并在单击时将其聚焦(在Mac Human Interface Guidelines中提到)。 They are common in most programs. 它们在大多数程序中很常见。
How could I do this? 我该怎么办? So far I think using a HashMap and WindowAdapters , that add and remove when windows appear, but I can't work out how to implement this. 到目前为止,我认为我使用的是HashMap和WindowAdapters ,它们会在窗口出现时添加和删除,但是我无法弄清楚如何实现它。
Note - I have a main frame, and dialogs that are called in separate classes from the main frame which would have the menu. 注意-我有一个主框架,并且对话框与要具有菜单的主框架在不同的类中调用。 Sorry, no especially relevant code that helps explain. 抱歉,没有特别相关的代码可以帮助解释。 I am aware of Window.getWindows() but unsure how this would be used. 我知道Window.getWindows(),但不确定如何使用。
How to Use Actions is a good choice "if you have two or more components that perform the same function." “如果您有两个或多个执行相同功能的组件,那么如何使用动作是一个不错的选择。” Compete examples include these: 竞争示例包括:
FileMenu
, which illustrates a menu of files. FileMenu
,它说明文件菜单。
ImageApp
, which opens images from a menu bar or a context menu. ImageApp
,从菜单栏或上下文菜单打开图像。
InternalFrameFocus
, a JInternalFrame
example cited there shows how to use setSelected()
in a menu's Action
. InternalFrameFocus
引用的JInternalFrame
示例InternalFrameFocus
显示了如何在菜单的Action
使用setSelected()
。
Action action = new AbstractAction(name) { @Override public void actionPerformed(ActionEvent ae) { try { MyFrame.this.setSelected(true); } catch (PropertyVetoException e) { e.printStackTrace(); } } };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.