• Post Reply Bookmark Topic Watch Topic
  • New Topic

action events  RSS feed

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys,
i want to perform this action. say for example, there is a "search button" and i want to get the search button activated when i press "enter" button on the key board. please replay soon.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JRootPane().setDefaultButton(JButton);
Then of course you need an ActionListener registered on your JButton with an ActionEvent.
If you are just using a JPanel, you can get the root pane as follows
myPanel.getRootPane()
Hope that helps.
BTW - This probably goes in the JFS/Swing/AWT forum.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
Then of course you need an ActionListener registered on your JButton with an ActionEvent.

To do that:
1. Create an instance of your Button in the GUI code.
2. Create an instance of a Listener that does whatever you want it to. (You may need to write your own class here, and then create an instance of it in your GUI code).
3. Link them together in the GUI using
myButton.addActionListener(myListener);
Moving to the Swing forum.
[ February 18, 2003: Message edited by: Cindy Glass ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!