Article View: borland.public.jbuilder.java.swing
Article #9550Re: Default (Enter) button?
From: Johan Forsberg
Date: Tue, 14 Mar 2000 00:00
Date: Tue, 14 Mar 2000 00:00
24 lines
1476 bytes
1476 bytes
Nils-Erik Thorell <net@es.sigma.se> skrev i
diskussionsgruppsmeddelandet:38CCCF1F.41F27E72@es.sigma.se...
> In a DialogBox or a Frame with textfields and an Ok button,
> I want to be able to hit 'Enter' at any point in time to terminate
> the input.
> In other words, the Ok-button should be sensitive to 'Enter',
> (and the Cancel button should be mapped to the 'Esc'-key)
>
> all other keys should go to the textfields.
If your JButtons are named ok and cancel:
theFrame.getRootPane().setDefaultButton(ok); // You get a nice border too
theFrame.registerKeyboardAction(
new AbstractAction() {
public void actionPerformed(ActionEvent e) { cancel.doClick(); }
},
KeyStroke.getKeyStroke(KeyEvent.VK_ESC, 0, false),
JComponent.WHEN_IN_FOCUSED_WINDOW);
Warning: the enter key will NOT cause ok to be clicked if you are in a text
component. Not even if it is a single line JTextField.
Technical Details
Message-ID:
<8alppr$r041@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38CCCF1F.41F27E72@es.sigma.se>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,47068b53b479f796 X-Google-Attributes: gid111d45,public From: "Johan Forsberg" <jfo@SPAM_SPAM_EGGS_SPAMstmf.se> Subject: Re: Default (Enter) button? Date: 2000/03/14 Message-ID: <8alppr$r041@bornews.borland.com> X-Deja-AN: 597403327 References: <38CCCF1F.41F27E72@es.sigma.se> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing