0

I have a simple question; I am trying to add a menu to my program. This is what I have thus far:

public static void main(String args[]){
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {}
    JFrame cipherGUIFrame = new CipherGUIFrame();
    cipherGUIFrame.setVisible(true);

    JMenuBar bar = new JMenuBar();;
    JMenu file = new JMenu("File");
    JMenu edit = new JMenu("Edit");
    JMenuItem open = new JMenuItem("Open");
    JMenuItem save = new JMenuItem("Save");

    JMenuItem cut = new JMenuItem("Cut");
    JMenuItem copy = new JMenuItem("Copy");
    JMenuItem paste = new JMenuItem("Paste");
    JSeparator sep = new JSeparator();
    JMenuItem find = new JMenuItem("Find");
    JPopupMenu options = new JPopupMenu("Options");
    options.setVisible(true);

    file.add(open);
    file.add(save);

    edit.add(cut);
    edit.add(copy);
    edit.add(paste);
    edit.add(sep);
    edit.add(find);
    edit.add(options);

    bar.add(file);
    bar.add(edit);
    cipherGUIFrame.setJMenuBar(bar);
}

I am trying to achieve an effect similar to this diagram: https://i.stack.imgur.com/ObZKA.jpg .

Is "Options" not the JPopupMenu? It doesn't seem to show up! Or is it simply a JMenuItem and JPopupMenu is the new box that comes up when you hover over it?

Huang Lee
  • 53
  • 4

1 Answers1

0

A sub menu is just that, a menu which is contained within another menu

Try using something like...

JMenu options = new JMenu("Options");
options.add(new JRadioButtonMenuItem("Forward"));
options.add(new JRadioButtonMenuItem("Backward"));
options.addSeparator();
options.add(new JCheckBoxMenuItem("Case Sensetive"));

SubMenu

Take a closer look at How to Use Menus for more details

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366