Hi!

Does anybody know how to add MouseListener to JMenu? I have the following working code, however, as you may see, I have MenuListener that allows running "createBaseRight" after selecting (NOT CLICKING) JMenu: home. Thanks in advance!

JMenuBar menubar = new JMenuBar();
        this.setJMenuBar(menubar);
        JMenu home = new JMenu("Начальная страница");
        menubar.add(home);
//...
        menubar.add(admin);

        home.addMenuListener(new MenuListener() {
              public void menuSelected(MenuEvent e) {
                createBaseRight(1);
              }
              public void menuDeselected(MenuEvent e) {
              }
              public void menuCanceled(MenuEvent e) {
              }
        });

Recommended Answers

All 2 Replies

MouseListener to JMenu

What kind of MouseEvents are you interested in?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.