Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enable ENTER button in swing application  RSS feed

 
igwe kalu kalu ogba
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I've written a swing application with buttons. For my button, I added a mnemonic such that I added in my code:

button1.setMnemonic(KeyEvent.VK_ENTER);

But the problem I have with this is that the user has to press "Alt" then ENTER before the button is activated. Is there another way of enabling button1 such that when the user presses only ENTER on the keyboard, the button , button1 is activated, that is on pressing only ENTER not alt+enter. Thanks.
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set the default button on the container. See JRootPane.setDefaultButton()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!