Article View: borland.public.jbuilder.java.swing
Article #10739Re: Focus traversal on Enter key?
From: Terje Viken
Date: Tue, 17 Aug 1999 00:00
Date: Tue, 17 Aug 1999 00:00
73 lines
3106 bytes
3106 bytes
Hi!
Thank you for this example. However I had problems getting it to work. I
have no problems registering my Frame - components and all the code in>
EnterKeyAdapter.keyPressed < is called.
When the line:
"fm.focusNextComponent(frame.getFocusOwner());" - is called nothing happens.
The object that had the focus - still has the focus when the code has
finished.
I have checked that > frame.getFocusOwner() < - returns the correct
component.
My Frame class is extending DecoratedFrame. - What am I doing wrong?
Terje Viken
Norway
Christophe Caenevet <christophe_caenevet@bigfoot.com> wrote in message
news:7otutj$m95$1@nnrp1.deja.com...
> 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:
<xjau3.453$J_1.30269@juliett.dax.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7opftu$aal4@forums.borland.com> <7opra1$al11@forums.borland.com> <7otutj$m95$1@nnrp1.deja.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: "Terje Viken" <teviken@c2i.net> Subject: Re: Focus traversal on Enter key? Date: 1999/08/17 Message-ID: <xjau3.453$J_1.30269@juliett.dax.net> X-Deja-AN: 513732090 References: <7opftu$aal4@forums.borland.com> <7opra1$al11@forums.borland.com> <7otutj$m95$1@nnrp1.deja.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 X-Complaints-To: abuse@tele2.no X-Trace: juliett.dax.net 934883677 193.216.40.136 (Tue, 17 Aug 1999 11:54:37 MET DST) Organization: Tele2 Norway AS Public Access X-MSMail-Priority: Normal NNTP-Posting-Date: Tue, 17 Aug 1999 11:54:37 MET DST Newsgroups: borland.public.jbuilder.java.swing