Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6913

Re: event listener

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From "John B. Matthews" <nospam@nospam.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: event listener
Date Tue, 09 Aug 2011 10:38:41 -0400
Organization The Wasteland
Lines 23
Message-ID <nospam-A5EA5D.10384109082011@news.aioe.org> (permalink)
References <2e38eb6a-a835-4fdf-bebe-5fc2b4f17333@m4g2000pri.googlegroups.com>
NNTP-Posting-Host LQJtZWzu+iKlBROuDg+IUg.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
X-Notice Filtered by postfilter v. 0.8.2
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6913

Show key headers only | View raw


In article 
<2e38eb6a-a835-4fdf-bebe-5fc2b4f17333@m4g2000pri.googlegroups.com>,
 wee <rbulseco@gmail.com> wrote:

> I have a JButton object and I added an actionListener to it. It works 
> well with a mouse click, but if I use the enter key while the focus 
> is on the JButton, nothing happens. Do I need to add a keypress 
> listener on top of the actionListener to the JButton so that it would 
> work both for a keypress and a mouse click? Help on this query is 
> greatly appreciated.

The default key binding for Swing buttons is the space key [1]. You can 
add a binding to the enter key, as shown here [2], but the root pane's 
setDefaultButton() method [3] is a convenient alternative.

[1]<http://download.oracle.com/javase/tutorial/uiswing/misc/keybinding.html>
[2]<http://sites.google.com/site/drjohnbmatthews/keypad-panel>
[3]<http://download.oracle.com/javase/6/docs/api/javax/swing/JRootPane.html>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

event listener wee <rbulseco@gmail.com> - 2011-08-08 17:17 -0700
  Re: event listener "John B. Matthews" <nospam@nospam.invalid> - 2011-08-09 10:38 -0400

csiph-web