Article View: borland.public.jbuilder.java.swing
Article #10803Re: Focus traversal on Enter key?
From: Christophe Caenevet
Date: Thu, 12 Aug 1999 00:00
Date: Thu, 12 Aug 1999 00:00
50 lines
2324 bytes
2324 bytes
I've got a method to do it for all the components you want :
I make the folllowing class :
public class EnterKeyAdapter extends KeyAdapter {
Window frame ;
public EnterKeyAdapter ( Window _frame ){
frame = _frame;
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ENTER){
FocusManager fm = FocusManager.getCurrentManager();
if (fm instanceof DefaultFocusManager)
fm.focusNextComponent(frame.getFocusOwner());
}
}
}
to put this adapter I do the following code during the windowOpened
event :
(the pane to start this function is the result of GetContentPane())
private void addEnterKeyPressedEventListener( Container pane){
Component currentComponent ;
int count = pane.getComponentCount();
for (int index=0; index < count ; index ++ ){
currentComponent = pane.getComponent(index);
if ( !(currentComponent instanceof JPanel)
&& !(currentComponent instanceof JButton)
&& !(currentComponent instanceof JLabel)
)
currentComponent.addKeyListener(new EnterKeyAdapter(this));
if ( currentComponent instanceof JPanel)
addEnterKeyPressedEventListener((Container)currentComponent);
}
}
--
===============================================
Professionnal : christophe_caenevet@bigfoot.com
Personnal : caenevet_xelot@bigfoot.com
===============================================
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Technical Details
Message-ID:
<7otutj$m95$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7opftu$aal4@forums.borland.com> <7opra1$al11@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,9fed77d5e06193b9 X-Google-Attributes: gid111d45,public From: Christophe Caenevet <christophe_caenevet@bigfoot.com> Subject: Re: Focus traversal on Enter key? Date: 1999/08/12 Message-ID: <7otutj$m95$1@nnrp1.deja.com> X-Deja-AN: 511759876 References: <7opftu$aal4@forums.borland.com> <7opra1$al11@forums.borland.com> X-Http-Proxy: 1.0 x37.deja.com:80 (Squid/1.1.22) for client 195.115.40.226 Organization: Deja.com - Share what you know. Learn what you don't. X-Article-Creation-Date: Thu Aug 12 07:59:50 1999 GMT X-MyDeja-Info: XMYDJUIDcaenevetc Newsgroups: borland.public.jbuilder.java.swing X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)