D. Clayton
D. Clayton

Reputation: 277

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, 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.

Upvotes: 0

Views: 133

Answers (1)

trashgod
trashgod

Reputation: 205875

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();
            }
        }
    };
    

Upvotes: 2

Related Questions