Contextual Menu in an Applet

Discussion in 'Java' started by Gerry, Feb 23, 2005.

  1. Gerry

    Gerry Guest

    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?

    --
    http://www.mts.net/~gbeggs1/
     
    Gerry, Feb 23, 2005
    #1
    1. Advertising

  2. Gerry

    Nigel Wade Guest

    Gerry wrote:

    > 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.

    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
     
    Nigel Wade, Feb 24, 2005
    #2
    1. Advertising

  3. Gerry

    Gerry Guest

    > 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.

    --
    http://www.mts.net/~gbeggs1/
     
    Gerry, Feb 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Developer Relations

    Blog Musing: "contextual usage patterns"

    Developer Relations, Jan 6, 2004, in forum: Java
    Replies:
    1
    Views:
    417
    Andrew Thompson
    Jan 7, 2004
  2. Squid Seven
    Replies:
    2
    Views:
    4,685
    Squid Seven
    Apr 6, 2005
  3. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    Inserting a contextual JS function in a DataGrid LinkButton

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 18, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    393
    Walter Wang [MSFT]
    Jun 19, 2006
  4. Daniel Pitts
    Replies:
    4
    Views:
    347
    Roland Pibinger
    Oct 13, 2007
  5. Vinay Sajip
    Replies:
    2
    Views:
    329
    Vinay Sajip
    Jan 8, 2008
Loading...

Share This Page