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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:18:27+00:00 2026-05-20T07:18:27+00:00

They don’t have setMnemonic(), as Buttons do. I’m trying to build some automated UI

  • 0

They don’t have setMnemonic(), as Buttons do.

I’m trying to build some automated UI testing. Making the entire UI keyboard driven is vital for this. Using mnemonics (accelerators or shortcuts) to move between widgets is a tried and true method.

I can’t seem to figure out how to set a mnemonic for the above components though.
There are ways to brute-force the keyboard navigation, tabbing between elements or manually register global accelerators. But if I have to go that far I’d at least like some opinions on the best practice for this.

<edit>

camickr was right. I just had to relax and finish reading the docs on the subject. then it became quite simple. Here’s is the final result for anyone doing a search.

treeWidget                                     
  .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
  .put(KeyStroke.getKeyStroke(LIST_MN,InputEvent.ALT_DOWN_MASK), "focus_jtree");

treeWidget   
  .getActionMap()                        
  .put("focus_jtree", new AbstractAction() {
    @Override                    
    public void actionPerformed(ActionEvent event) {
      treeWidget.requestFocusInWindow();
  }});
  • 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-20T07:18:27+00:00Added an answer on May 20, 2026 at 7:18 am

    See the Swing tutorial in How to Use Key Bindings.

    But I can’t seem to figure out how to set focus to one of these components using only keyboard events.

    Not sure what you mean by that. You can tab to any of those components.

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

Sidebar

Related Questions

I'm trying to build an RPM that will install file dependencies if they don't
Sorry I saw similar questions but they don't seem to have some full answers
I have this view hierarchy: The three buttons don't response. They are enabled, just
Trying to write out syslog entries containing strings but they don't register. // person.name
My hosting service just informed me that they don't have Git installed on any
I have a third party COM component (they don't offer a .Net assy), that
How to generate random integers but making sure that they don't ever repeat? For
I have checked similarly named questions, but they don't answer this use case. Basically,
I have Listpreferences in my app. They don't appear to be setting to their
I looked through ApplicationListener , and they don't have it in there. On a

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.