Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8437051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:19:51+00:00 2026-06-10T07:19:51+00:00

The JMenuBar does not start showing JMenuItem s as selected or displaying the JMenu

  • 0

The JMenuBar does not start showing JMenuItems as selected or displaying the JMenu popups until it is first clicked upon. After you click somewhere in the JMenuBar, all these items respond to mouse hovers.

I would like to bypass the initial click required and have it activated automatically upon a mouse hover. Is there a way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:19:52+00:00Added an answer on June 10, 2026 at 7:19 am

    The way is to add a MouseListener on the JMenu and listen on events mouseEntered. In the event handlers, you just need to click on it using doClick. For example,

    jMenuFile.addMouseListener(new MouseListener(){
        public void mouseEntered(MouseEvent e) {
           jMenuFile.doClick();
        }
      ...
    });
    

    Once programmatically clicked on the mouse is entered, it opens the popup menu automatically. To activate an entire JMenuBar, you have to add a listener on each JMenu. For this purpose, it is better to create a listener object separately.

    I have two menu items on the bar, so I did:

    MouseListener ml = new MouseListener(){
        public void mouseClicked(MouseEvent e) {}
        public void mousePressed(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
        public void mouseExited(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {
            ((JMenu)e.getSource()).doClick();
        }
      };
      jMenuFile.addMouseListener(ml);
      jMenuHelp.addMouseListener(ml);
    

    If you have so many menu items on the bar, you can just iterate it:

    for (Component c: jMenuBar1.getComponents()) {
        if (c instanceof JMenu){
            c.addMouseListener(ml);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; @SuppressWarnings(serial) public class Main extends JFrame
I'm developping a Java/Swing application with a menu using JMenuBar, JMenu and JMenuItem. System
my JMenuBar is not showing AT ALL. This is just a barebones GUI. I
The JMenuItems of JMenuBar drops down to a JPanel added to the JFrame, but
I'm trying to move the menu structure from a JMenu into a JMenuBar. The
Is there any way to auto-select a jmenu within my jmenubar when the user's
I have written code to perform click event on JMenuItem but that is not
menuBar = new JMenuBar(); // File Menu JMenu fileMenu = new JMenu(File); menuBar.add(fileMenu); //
import org.jdesktop.application.SingleFrameApplication; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem;
I have a program that is not showing any errors in Eclipse, but whenever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.