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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:22:11+00:00 2026-05-27T10:22:11+00:00

I am implementing some keyboard code for an existing java swing application, but I

  • 0

I am implementing some keyboard code for an existing java swing application, but I can’t seem to get a keyboard press to execute the “mousePressed” action and “mouseReleased” action that are mapped to a JButton. I have no problems clicking it for the “action_performed” with button.doClick(), is there a similar function for simulating the mouse presses? Thanks beforehand.

  • 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-27T10:22:12+00:00Added an answer on May 27, 2026 at 10:22 am

    You can simulate mouse presses and mouse actions by using the Robot class. It’s made for simulation e.g. for automatically test user interfaces.

    But if you want to share “actions” for e.g. buttons and keypresses, you should use an Action. See How to Use Actions.

    Example on how to share an action for a Button and a Keypress:

    Action myAction = new AbstractAction("Some action") {
    
        @Override
        public void actionPerformed(ActionEvent e) {
            // do something
        }
    };
    
    // use the action on a button
    JButton myButton = new JButton(myAction);  
    
    // use the same action for a keypress
    myComponent.getInputMap().put(KeyStroke.getKeyStroke("F2"), "doSomething");
    myComponent.getActionMap().put("doSomething", myAction);    
    

    Read more about Key-bindings on How to Use Key Bindings.

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

Sidebar

Related Questions

I'm implementing some code using the java.util.concurrency framework. I will be passing a collection
I am an iOS development newbie. I am implementing some sample code, but try
I'm implementing some basic ranking functionality in my MVC application, but I'm running across
I'm implementing some code generators, i would like to know if there's any way
I had some troubles implementing Lawler's algorithm but thanks to SO and a bounty
I am implementing one application some fields are edittext in edittext clicking open mobile
I'm implementing some networking code using the selector pattern in C# / .NET 3.5.
I'm currently implementing some image processing code for Android. I'm aware of the memory
I'm currently implementing a software keyboard ( using some sophisticated prediction ), and drawing
I'm looking at implementing some LINQ to SQL but am struggling to see how

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.