Search code examples
javaswingjframejbutton

How to press a jButton using keyboard key in Java?


I'm writing a simple calculator program using jFrame. I would like to press the numbers by my keyboard instead of clicking on it by my mouse... How could I do this ? My Simple Calculator


Solution

  • You just have to change a property to JButton, to get a short path

    Exmple :

       buttonOne.setMnemonic(KeyEvent.VK_C);