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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:41:15+00:00 2026-06-13T04:41:15+00:00

Ok, so I’m trying to Unit test some GUI elements I have a JButton

  • 0

Ok, so I’m trying to Unit test some GUI elements I have a JButton with text of “Create” and the mnemonic set on ‘C’ or code 67. I can write a unit test that I can call the .doClick function on and assert that what that button is supposed to do, happens.

However, I now want to write a unit test to test that the mnemonic portion of that same button works identically to the button click. I’ve searched on and off for a couple of days now and have tried many things.

I’ve tried using Robot from the awt library:

robot.keyPress(KeyEvent.VK_C);
robot.keyRelease(KeyEvent.VK_C);

To which no event is being triggered and most recently I’ve tried this EventQueue example:

final Toolkit toolkit = Toolkit.getDefaultToolkit();
final EventQueue eventQueue = toolkit.getSystemEventQueue();
gPane = new SwingBuilder();
panel = new MainMenuPanel();
panel.displayMainMenu(gPane); 

@Test
void ShouldMakeRaceGenderPanelVisibleKeyPress(){
eventQueue.postEvent( new KeyEvent(panel.gPane.mainM, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, KeyEvent.VK_C ).getKeyCode());

    assertThat panel.gPane.mainM.isVisible(), is(false);
    assertThat panel.gPane.raceGender.isVisible(), is(true);
}

I know that GUI testing can be tricky and there are tools out there to simulate user interaction, but is it really that hard to simulate or trigger just a single KeyEvent?

Any assistance is welcome, and any UI testing tools recommended is welcome as well.

Thanks

Note: This is a combination of Java and Groovy, so I’m using SwingBuilder to build my UI’s

  • 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-13T04:41:16+00:00Added an answer on June 13, 2026 at 4:41 am

    You state:

    I have a JButton with text of “Create” and the mnemonic set on ‘C’ or code 67. …
    However, I now want to write a unit test to test that the mnemonic portion of that same button works identically to the button click. …

    I’ve tried using Robot from the awt library:

    robot.keyPress(KeyEvent.VK_C);
    robot.keyRelease(KeyEvent.VK_C);
    

    Perhaps the problem is due to your not taking into account that JButton mnemonics are alt-key combinations, and so your robot code would probably have to reflect this:

    robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_C);
    
    // possibly want a small Thread.sleep(...) here?
    
    robot.keyRelease(KeyEvent.VK_C);
    robot.keyRelease(KeyEvent.VK_ALT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put

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.