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
SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
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.
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
The best teams have no specialists, only general contributors with special skills
I found some pretty shells, some sea glass and this lovely tiny ad:
Gift giving made easy with the permaculture playing cards