Article View: borland.public.jbuilder.java.swing
Article #9422Re: Default (Enter) button?
From: Petr Kozelka
Date: Wed, 15 Mar 2000 00:00
Date: Wed, 15 Mar 2000 00:00
47 lines
2007 bytes
2007 bytes
"Tor Iver Wilhelmsen" <tor.wilhelmsen@sds.no> wrote in message
news:uvh2oimof.fsf@sds.no...
> "Petr Kozelka" <pkozelka@email.cz> writes:
>
> > Isn't there any more elegant way ?
> > What if I have twenty text fields in the form ? And it is not so
unusual...
>
> The alternative is to alter the JTextFields' Keymap - which is less
> elegant. :-)
>
> But what's so unelegant about
>
> ActionListener act = new ActionListener() {
> // Implementation
> };
>
>
> okButton.addActionListener(act);
> jTextField1.addActionListener(act);
> // ...
what I find unelegant is this:
jTextField1.addActionListener(act);
jTextField2.addActionListener(act);
jTextField3.addActionListener(act);
jTextField4.addActionListener(act);
jTextField5.addActionListener(act);
jTextField6.addActionListener(act);
jTextField7.addActionListener(act);
jTextField8.addActionListener(act);
.
.
.
In real, the names would probably not be just number-indexed default name,
so it is even more easy to forget one of them.
What I mean by elegant is catching the ENTER and ESC at window level.
What if I want to have seven shortcuts in a complex dialog ? Am I supposed
to connect all shortcut handlers with all text fields manually ?
I admit very little experience with JAVA GUI so maybe I am missing something
trivial.
Thanks,
Petr
Technical Details
Message-ID:
<8anmpp$scp3@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38CCCF1F.41F27E72@es.sigma.se> <8alppr$r041@bornews.borland.com> <u3dpsk6ar.fsf@sds.no> <8anh38$s163@bornews.borland.com> <uvh2oimof.fsf@sds.no>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,47068b53b479f796 X-Google-Attributes: gid111d45,public From: "Petr Kozelka" <pkozelka@email.cz> Subject: Re: Default (Enter) button? Date: 2000/03/15 Message-ID: <8anmpp$scp3@bornews.borland.com> X-Deja-AN: 597740544 References: <38CCCF1F.41F27E72@es.sigma.se> <8alppr$r041@bornews.borland.com> <u3dpsk6ar.fsf@sds.no> <8anh38$s163@bornews.borland.com> <uvh2oimof.fsf@sds.no> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing