🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #9292

Help registering a keyboard action for a button

#9292
From: Jeff Marendo
Date: Mon, 24 Apr 2000 00:00
27 lines
1829 bytes
Hello,

I made a button that extends from JButton that shows different images
depending on the button's state. All of that stuff is working good. My
problem relates to the fact that one cannot activate buttons automatically
with the 'Enter' keys when the buttons are in a panel that is using the
Metal or Motif Look & Feel in an applet. I posted this problem a while ago
and had a good response from someone with a solution like below:

...
JButton button = new JButton("hit Return");
button.registerKeyboardAction(button.getActionForKeyStroke(KeyStroke.getKeyS
troke(KeyEvent.VK_SPACE,0,true)),
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,true) ,
JComponent.WHEN_FOCUSED );

button.registerKeyboardAction(button.getActionForKeyStroke(KeyStroke.getKeyS
troke(KeyEvent.VK_SPACE,0,false)),
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,false),JComponent.WHEN_FOCUSED );
...

I would like to handle this problem by including this code in my class that
I've built. Unfortunately, just replacing the JButton variable "button" with
"this" won't do the trick. Does anyone have an idea how I can register the
keyboard action I want inside my class so that it's taken care of when an
instance of it is made? Thanks in advance.
Jeff
Technical Details
Message-ID: <39048b1c@dnews>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,c903aea1d8ad6d2c,start
X-Google-Attributes: gid111d45,public
From: "Jeff Marendo" <marendoj@commos.com>
Subject: Help registering a keyboard action for a button 
Date: 2000/04/24
Message-ID: <39048b1c@dnews>
X-Deja-AN: 615063801
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
X-Trace: 24 Apr 2000 10:57:48 -0800, 24.95.56.21
Organization: CommTech Corporation
X-MSMail-Priority: Normal
Reply-To: "Jeff Marendo" <marendoj@commos.com>
Newsgroups: borland.public.jbuilder.java.swing