Contextual Menu in an Applet

G

Gerry

I'm trying to use a contextual (right-click) menu in my applet.
It is working fine when I run it on a Mac.

But on Windows, the menu is not showing up.

The code I'm using from within my mousePressed method is:

if (e.isPopupTrigger())
{
popupMenu.show(this, e.getX(), e.getY());
}

It is handling regular (left-click) mouse presses correctly. It just
doesn't seem to be returning TRUE from e.isPopupTrigger() when I do a
right-click.


Any idea on what I might be doing wrong?
Or are contextual menus not widely supported for applets?
 
N

Nigel Wade

Gerry said:
I'm trying to use a contextual (right-click) menu in my applet.
It is working fine when I run it on a Mac.

But on Windows, the menu is not showing up.

The code I'm using from within my mousePressed method is:

if (e.isPopupTrigger())
{
popupMenu.show(this, e.getX(), e.getY());
}

It is handling regular (left-click) mouse presses correctly. It just
doesn't seem to be returning TRUE from e.isPopupTrigger() when I do a
right-click.


Any idea on what I might be doing wrong?
Or are contextual menus not widely supported for applets?

It should work perfectly. I use e.isPopupTrigger() in applets which work on
Linux, MacOS, Windows. All using the Sun 1.4.2 JVM, BTW. This is a code
snippet:

JPopupMenu popup;
...
this.addMouseListener(new PopupListener());
...


class PopupListener extends MouseAdapter {
public void mousePressed(MouseEvent e) {

if (e.getButton() == MouseEvent.BUTTON1) {
// do button1 actions
} else {
maybeShowPopup(e);
}
}
...
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
int mouseX = e.getX();
int mouseY = e.getY();
popup.show(e.getComponent(), mouseX, mouseY);
}
}
}


I suspect there is something else wrong, either in the the rest of your code
or the JVM which is installed on the Windows machine.
 
G

Gerry

It should work perfectly. I use e.isPopupTrigger() in applets which work on
Linux, MacOS, Windows. All using the Sun 1.4.2 JVM, BTW. This is a code
snippet:

JPopupMenu popup;
...
this.addMouseListener(new PopupListener());

This is the only line which differs from my code.
I am trying to stick to Java 1.1 so that I can run on older machines and
the PopupMenuListener interface doesn't seem to be part of Java 1.1.

I'm reading a Java 1.1 book and it shows pop-up menus working without
using the PopupMenuListener interface.
I suspect there is something else wrong, either in the the rest of your code
or the JVM which is installed on the Windows machine.

Is there a way I could work around this to make it work on newer JVM's
and still have it work on Java 1.1 machines?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top