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 5984265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:21:01+00:00 2026-05-22T22:21:01+00:00

Edit Downvoter, how is this a bad question? I have provided runnable example code

  • 0

Edit
Downvoter, how is this a bad question? I have provided runnable example code of the issue. If it works for you please let me know or point out what is unclear.

Hello,
in the code below which has a single JComboBox in a JFrame, I am not notified when the mouse enters the JComboBox or is clicked or focus gained. However, the PopupMenuEvent works properly.

What am I doing wrong? (My goal is to be alerted when the text component of the JComboBox is clicked)

public class TestJComboBox extends javax.swing.JFrame
{
    public TestJComboBox()
    {
        initComponents();
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });

        jComboBox1.setEditable(true);
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.setName("jComboBox1"); // NOI18N
        jComboBox1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox1MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jComboBox1MouseEntered(evt);
            }
        });
        jComboBox1.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBox1PopupMenuWillBecomeVisible(evt);
            }
        });
        jComboBox1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jComboBox1FocusGained(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(104, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(90, 90, 90)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(164, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void jComboBox1FocusGained(java.awt.event.FocusEvent evt)
    {
        System.out.println("JComboBox Focus gained");
    }

    private void formMouseClicked(java.awt.event.MouseEvent evt)
    {
        System.out.println("Form clicked");
        jComboBox1.setFocusable(false);
        jComboBox1.setFocusable(true);
    }

    private void jComboBox1MouseClicked(java.awt.event.MouseEvent evt)
    {
        System.out.println("JComboBox Click");
    }

    private void jComboBox1PopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt)
    {
        System.out.println("JComboBox Visible menu");
    }

    private void jComboBox1MouseEntered(java.awt.event.MouseEvent evt)
    {
        System.out.println("Entered JComboBox");
    }

    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new TestJComboBox().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JComboBox jComboBox1;
    // End of variables declaration
}

Thanks!

  • 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-05-22T22:21:01+00:00Added an answer on May 22, 2026 at 10:21 pm

    Possibly the downvoter took offense at your use of Netbeans GUI editor. I don’t like it myself, but you’re welcome to use it if you find that you can actually maintain a complex gui with it. I personally hate it due to various extremely annoying bugs that only show themselves when you’re trying to edit the form and it quietly loses your layout and component settings. But that’s beside the point.

    Anyway, you need to add your ActionListener like this:

    jComboBox1.getEditor().getEditorComponent().addMouseListener(...);
    

    JComboBox is really a composite component with a JTextField, JButton, and JList buried inside it, so you were adding the ActionListener to the wrapping component, when the mouse events are really going to the inner JTextField.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This question is more about language engineering than C++ itself. I used C++
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit: I have solved this by myself. See my answer below I have set
I know this won't be a popular question, because a lot of web designers
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
This is stemming from a bad answer I gave last night. The curiosity as
Well! I feel really stupid for this question, and I wholly don't mind if

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.