0

For user convenience, and after reading user interface guidelines, I would like a JMenu with Items as open Windows in my program, e.g. different (non-modal) dialogs/frames.

The menu lists the windows, and focuses them when clicked (Mentioned in 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.

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
D. Clayton
  • 277
  • 2
  • 10

1 Answers1

2

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.

  • ImageApp, which opens images from a menu bar or a context menu.

  • InternalFrameFocus, a JInternalFrame example cited there shows how to use setSelected() in a menu's Action.

    Action action = new AbstractAction(name) {
        @Override
        public void actionPerformed(ActionEvent ae) {
            try {
                MyFrame.this.setSelected(true);
            } catch (PropertyVetoException e) {
                e.printStackTrace();
            }
        }
    };
    
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045