• Post Reply Bookmark Topic Watch Topic
  • New Topic

action

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey world,
could you please tell how to do this. say i when i press the "enter" from the key board it should activate the "search button" i know it is something to do with the jrootpane. i am using a jpanel to add the buttons and stuff.please send a step by step reply.thanks cheers
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I won't give you a step by step solution, but here is how you do it:
Make your panel implement KeyListener, then when you get a key pressed event, and the source is the enter key(VK_ENTER I believe), call the method you want to perform the search. Look at the API and you should get an idea.
 
Ashish Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ransika,
I just wanna add my $0.02
What Chad said is right. But Sun guys have made our life easier by providing setDefaultButton(JButton) method in JRootPane. One reason why one would opt for setting default button is that - On Mac OS X the root pane's default button glows beautifully like a heart beat.
One point to be noted in this connection. JDK 1.3 has a bug in that if user is navigating the application menus with key board and presses "Enter" expecting that menu item's action getting fired but the default button's action gets fired. However they have fixed this bug in 1.4.
If u r developing for Mac OS X also then u may be worried about this 1.3 bug. Possible solution is to write a sublcass of JMenu say XMenu in it's init method add a MenuListener and in it's menuSelected(MenuEvent) method after taking a backup of default button set root pane's default button to null and in deselected method restore the default button.
Sincerely,
Ashish
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!