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

MouseEvent.isPopUpTrigger()

491 views
Skip to first unread message

Peter Eshkeri

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
java.awt.event.MouseEvent.isPopupTrigger() doesn't appear to work.

Does anyone know a way to tell if the right hand mouse button has been
clicked?

Thanks,

Peter
pesh...@nortelnetworks.com

Roger Tobin Reyelts

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
Peter Eshkeri <pesh...@nortelnetworks.com> wrote:

>java.awt.event.MouseEvent.isPopupTrigger() doesn't appear to work.
>
>Does anyone know a way to tell if the right hand mouse button has been
>clicked?

AFAIK, MouseEvent.isPopupTrigger() works fine under Sun's reference
JDK... Are you using someone elses?

God bless,
-Toby
--
Toby Reyelts
331107 Georgia Tech Station Atlanta Georgia 30332-1365
Internet: gt1...@prism.gatech.edu

Ralf Cichy

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
I managet it like that :

java.awt.event.MouseListener theMouseListener = new
java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent e) {
if (e.isMetaDown()) {
theJPopupMenu.show(table , e.getX(), e.getY());
}// end if
}
public void mouseEntered(java.awt.event.MouseEvent e) {
}
public void mouseExited(java.awt.event.MouseEvent e) {
}
public void mousePressed(java.awt.event.MouseEvent e){}
public void mouseReleased(java.awt.event.MouseEvent e) {}
};

bye Ralf

Peter Eshkeri wrote:

> java.awt.event.MouseEvent.isPopupTrigger() doesn't appear to work.
>
> Does anyone know a way to tell if the right hand mouse button has been
> clicked?
>

> Thanks,
>
> Peter
> pesh...@nortelnetworks.com


Juergen Kreileder

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
>>>>> Peter Eshkeri writes:

Peter> java.awt.event.MouseEvent.isPopupTrigger() doesn't appear
Peter> to work. Does anyone know a way to tell if the right hand
Peter> mouse button has been clicked?

isPopupTrigger is not for detecting right mouse button clicks, you
should use a test like
(e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK);
for that.

isPopupTrigger is there to detect if a given event is the popup
trigger on a system. Different platforms have different popup
triggers (e.g. Windows uses 'right button released', UNIX uses 'right
button pressed'), so you'll have to test for isPopupTrigger at least in
mousePressed and mouseClicked.


Juergen


Juergen Kreileder

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
>>>>> Ralf Cichy writes:

Ralf> I managet it like that :
Ralf> java.awt.event.MouseListener theMouseListener = new
Ralf> java.awt.event.MouseAdapter() {

Ralf> public void mouseClicked(java.awt.event.MouseEvent e) {
Ralf> if (e.isMetaDown()) {
Ralf> theJPopupMenu.show(table , e.getX(), e.getY());
Ralf> }// end if
Ralf> }
Ralf> public void mouseEntered(java.awt.event.MouseEvent e) {
Ralf> }
Ralf> public void mouseExited(java.awt.event.MouseEvent e) {
Ralf> }
Ralf> public void mousePressed(java.awt.event.MouseEvent e){}
Ralf> public void mouseReleased(java.awt.event.MouseEvent e) {}
Ralf> };

That's not the correct way: Test for e.isPoppupTrigger both in
mousePressed and mouseClicked.


Juergen

--
Juergen Kreileder, Blackdown Java-Linux Porting Team
http://www.blackdown.org/java-linux.html

Biju Thomas

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
Juergen Kreileder wrote:

>
> >>>>> Ralf Cichy writes:
>
> Ralf> public void mouseClicked(java.awt.event.MouseEvent e) {
> Ralf> if (e.isMetaDown()) {
> Ralf> theJPopupMenu.show(table , e.getX(), e.getY());
>
> That's not the correct way: Test for e.isPoppupTrigger both in
> mousePressed and mouseClicked.

What is the problem with the 'isMetaDown()' method?

--
Biju Thomas

Juergen Kreileder

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
>>>>> Biju Thomas writes:

Biju> Juergen Kreileder wrote:
>>
>> >>>>> Ralf Cichy writes:
>>
Ralf> public void mouseClicked(java.awt.event.MouseEvent e) {
Ralf> if (e.isMetaDown()) {
Ralf> theJPopupMenu.show(table , e.getX(), e.getY());
>>
>> That's not the correct way: Test for e.isPoppupTrigger both in
>> mousePressed and mouseClicked.

Biju> What is the problem with the 'isMetaDown()' method?

It's the wrong concept, isMetaDown is the same on all platforms but
the popup trigger may be different on different platforms (Windows vs
UNIX). The above code pops up the menu on mouse release which is
very unnaturally on UNIX.


Juergen

Mr. Tines

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
In article <37E7B607...@nortelnetworks.com>, Peter Eshkeri
<pesh...@nortelnetworks.com> writes
>java.awt.event.MouseEvent.isPopupTrigger() doesn't appear to work.
>
>Does anyone know a way to tell if the right hand mouse button has been
>clicked?

If you wish to trigger a pop-up do this test in both mousePressed and
mouseReleased (some OS's do the pop-up on press, others on release). If
you just want the right hand button (and you have allowed for Mac users
who only have the one button), then isMetaDown() in any mouse event
handler will do.

-- PGPfingerprint: BC01 5527 B493 7C9B 3C54 D1B7 248C 08BC --
_______ {pegwit v8 public key =581cbf05be9899262ab4bb6a08470}
/_ __(_)__ ___ ___ {69c10bcfbca894a5bf8d208d001b829d4d0}
/ / / / _ \/ -_|_-< http://www.ravnaandtines.com/
/_/ /_/_//_/\__/___/@ravnaandtines.com PGP key on page

lowtech

unread,
Sep 22, 1999, 3:00:00 AM9/22/99
to

In article <k0f35ZAg...@windsong.demon.co.uk>,
"Mr. Tines" <ti...@ravnaandtines.com> wrote:

> If you wish to trigger a pop-up do this test in both mousePressed and
> mouseReleased (some OS's do the pop-up on press, others on release).

I think the right way to say is - "different Windowing Systems (not
neccessarily different OSs) have different established
standards/conventions as to which MouseEvent (press or release)
should popup the Popup Menus". And it is generally a good idea
to stick with standards of a given platform and not surprise the user.

I think isPopupTrigger() was a good attempt by the AWT engineers
to capture that abstraction but they did not go far enough. IMHO
the right way to implement would have been to define an even higher
level abstraction like PopupTriggerEvent and respective add and remove
listeners in the java.awt.Component class (similar to the
ActionPerformed abstraction which works with Mouse as well as
Keyboard). The Component.processEvent() method could have fired the
PopupTriggerEvent whenever any InputEvent (mouse, keyboard or
input method event) qualified as the popup trigger. The JCompoent's
processEvent() could have overridden the behaviour to take into
account that JComponent's "look and feel" to achieve a true "feel"
consistent with it's "look and feel".

In fact I had filed an RFE about this at JDC.

Anyways there is some help in Kerstel (JDK1.3)
in the form of JPopupMenu.isPopupTrigger() method.
It takes into account the "look and feel" of the
JPopupMenu. IMHO though this is once again
incorrect approach. The "look and feel" of the
JComponent on which one wants to show the popup
menu should be taken in to account not the
"look and feel" of the popup menu itself.
My biggest problem is that once this API gets out
there it is hard to change it. If only someone at Sun was
listening.... :(

My two cents.

-sandip

> If you just want the right hand button (and you have allowed for Mac
users
> who only have the one button), then isMetaDown() in any mouse event
> handler will do.
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

0 new messages