• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

action

 
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I found some pretty shells, some sea glass and this lovely tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic