Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Ctrl-click a button

3 views
Skip to first unread message
Message has been deleted

Lothar Kimmeringer

unread,
Dec 21, 2009, 1:32:45 PM12/21/09
to
Luc Van Bogaert wrote:

> I'm wondering how one could detect if a button (say a toolbar button)
> was clicked while the ctrl-key was held down. Is it possible to
> detect this modifier key in the actionPerformed() method of the
> action button itself?

I don't know (but other might) but if not, it should be possible
to add a KeyListener that gets this information independent from
the button being called. Setting an internal member in such a
case (and setting it back if the ctrl-key is released) should
allow you to "simulate" the modifier-information in actionPerformed.

Knowing if you speak of SWT, Swing or other GUI-frameworks
(e.g. GWT) might help answering that question as well ;-)


Regards, Lothar
--
Lothar Kimmeringer E-Mail: spam...@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!

Knute Johnson

unread,
Dec 21, 2009, 1:57:05 PM12/21/09
to
On 12/21/2009 10:15 AM, Luc Van Bogaert wrote:
> Hi,

>
> I'm wondering how one could detect if a button (say a toolbar button)
> was clicked while the ctrl-key was held down. Is it possible to
> detect this modifier key in the actionPerformed() method of the
> action button itself?
>
> Thanks,
>

I did this once by using a KeyListener that toggled a class variable
when the CTRL key was pressed. Then in the ActionListener I checked the
value of the variable. I also remember there was somebody else at the
time that posted an even better solution but I can't remember what it
was. I have no clue what you could search for to find it though.

--

Knute Johnson
email s/nospam/knute2009/


--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Roedy Green

unread,
Dec 21, 2009, 1:58:55 PM12/21/09
to
On 21 Dec 2009 18:15:47 GMT, Luc Van Bogaert <l...@rixhon.be> wrote,
quoted or indirectly quoted someone who said :

>I'm wondering how one could detect if a button (say a toolbar button)
>was clicked while the ctrl-key was held down. Is it possible to
>detect this modifier key in the actionPerformed() method of the
>action button itself?

see http://mindprod.com/products2.html#KEYPLAYER
--
Roedy Green Canadian Mind Products
http://mindprod.com
If you think it�s expensive to hire a professional to do the job, wait until you hire an amateur.
~ Red Adair (born: 1915-06-18 died: 2004-08-07 at age: 89)

Fred

unread,
Dec 21, 2009, 2:27:28 PM12/21/09
to
On Dec 21, 10:58 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:

> On 21 Dec 2009 18:15:47 GMT, Luc Van Bogaert <l...@rixhon.be> wrote,
> quoted or indirectly quoted someone who said :
>
> >I'm wondering how one could detect if a button (say a toolbar button)
> >was clicked while the ctrl-key was held down. Is it possible to
> >detect this modifier key in the actionPerformed() method of the
> >action button itself?
>
> seehttp://mindprod.com/products2.html#KEYPLAYER

The actionPerformed() method is passed an ActionEvent instance;
its getModifiers() method will tell all.
--
Fred K

markspace

unread,
Dec 21, 2009, 3:25:14 PM12/21/09
to
Luc Van Bogaert wrote:
> Hi,
>
> I'm wondering how one could detect if a button (say a toolbar button)
> was clicked while the ctrl-key was held down. Is it possible to
> detect this modifier key in the actionPerformed() method of the
> action button itself?


Yes. As Fred said (he replied to Roedy, so I'm replying to you just to
make sure you don't miss it), call getModifiers() inside
actionPerformed() to access the control key state:

actionEvent.getModifiers() & ActionEvent.CTRL_MASK

<http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html>

Knute Johnson

unread,
Dec 21, 2009, 3:51:36 PM12/21/09
to

Come to think of it, that was probably the better solution :-).

--

Knute Johnson
email s/nospam/knute2010/

Message has been deleted
0 new messages