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

  • Home
  • SEARCH
  • 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 8881533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:22:00+00:00 2026-06-14T20:22:00+00:00

I have a JComboBox with multiple values in it. How to detect the keystroke

  • 0

I have a JComboBox with multiple values in it. How to detect the keystroke control-option-space to open a pop-up window of JComboBox in MAC?

  • 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-14T20:22:01+00:00Added an answer on June 14, 2026 at 8:22 pm

    It’s not clear if you want the control-option-space key binding in addition to, or instead of, the standard space key. In either case, you can evoke the aquaSpacePressed action using a binding such as the one shown below. See How to Use Key Bindings for details.

    combo.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
        KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,
            KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK),
        "aquaSpacePressed");
    

    Because this is Mac-specific, you may want to use a predicate such as this:

    System.getProperty("os.name").startsWith("Mac OS X")
    

    Addendum: The sscce below was used to test the scenario in the revised question.

    Addendum: For reasons that are not clear, enabling System Preferences > Speech > Text to Speech preempts the control-option-space binding. As an alternative, you can bind to the standard Action, "spacePopup", shown in the revised example below.

    import java.awt.EventQueue;
    import java.awt.event.KeyEvent;
    import javax.swing.JComboBox;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.KeyStroke;
    
    /**
     * @see http://stackoverflow.com/a/13412208/230513
     */
    public class ComboKeyTest extends JPanel {
    
        public ComboKeyTest() {
            JComboBox cpmbo = new JComboBox();
            cpmbo.addItem("One");
            cpmbo.addItem("Two");
            cpmbo.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
                KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,
                KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK),
                "spacePopup");
    
            this.add(cpmbo);
        }
    
        private void display() {
            JFrame f = new JFrame("NewJavaGUI");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(this);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new ComboKeyTest().display();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jcombobox in my application. and i want it to support multiple
I have a Form with multiple different controls like ComboBox , TextBox and CheckBox
I have a JTable with two columns and both are JComboBox, for this purpose
I do have a strange focus problem when using a JComboBox inside an embedded
I have a little problem. I had some JComboBox to a JDialog but they
I have a combobox in a WPF Window, it is filled with usernames from
I have the following scenario. I have a combobox where multiple selection is available.
I have a UserControl with a Tab Control containing three tabs. Within the tabs
Is it possible to have a button having multiple options. I mean, its like
I have JComboBox with 2 columns and I have JButton . When I click

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.