Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:30:29+00:00 2026-06-04T02:30:29+00:00

I want to create a pop-up menu, which will appear if i right clicked

  • 0

I want to create a pop-up menu, which will appear if i right clicked on the canvas . How can I do this? which function should i modify? Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:30:30+00:00Added an answer on June 4, 2026 at 2:30 am

    Following code will create a popup menu when right-clicking either on the vertex or on the canvas…

    /**
     * a GraphMousePlugin that offers popup
     * menu support
     */
    protected class PopupGraphMousePlugin extends AbstractPopupGraphMousePlugin
    implements MouseListener {
    
        public PopupGraphMousePlugin() {
            this(MouseEvent.BUTTON3_MASK);
        }
        public PopupGraphMousePlugin(int modifiers) {
            super(modifiers);
        }
    
        /**
         * If this event is over a station (vertex), pop up a menu to
         * allow the user to perform a few actions; else, pop up a menu over the layout/canvas
         *
         * @param e
         */
        protected void handlePopup(MouseEvent e) {
            final VisualizationViewer<GeoLocation.Station,GeoLocation.Link> vv =
                    (VisualizationViewer<GeoLocation.Station,GeoLocation.Link>)e.getSource();
            final Point2D p = e.getPoint();
            final Point2D ivp = p;
    
            GraphElementAccessor<GeoLocation.Station,GeoLocation.Link> pickSupport = vv.getPickSupport();
            if(pickSupport != null) {
    
                JPopupMenu popup = new JPopupMenu();
    
                final GeoLocation.Station station = pickSupport.getVertex(vv.getGraphLayout(), ivp.getX(), ivp.getY());
    
                if(station != null) {
                    boolean isRadio = station.getParentSet().contains(STATION_IDENTIFIER_KEY);
    
                    if(isRadio)
                        if (station.getId().equalsIgnoreCase(SneakPeek.getUsername())){
    
                            String follow = "Follow " + station.getId();
                            if (followLocal){
                                follow = "Do not follow " + station.getId();
                            }
                            else {
                                follow = "Follow " + station.getId();
                            }
    
                            popup.add(new AbstractAction("<html><center>" + follow) {
                                public void actionPerformed(ActionEvent e) {
    
                                    followLocal = !followLocal;
    
                                }
                            });
    
                        }
    
                    if(popup.getComponentCount() > 0) {
                        popup.show(vv, e.getX(), e.getY());
                    }
                }
            }
            else { //to pop-up over the canvas/layout rather than over the station
    
                popup.add(new AbstractAction("Create Unit") {
                    public void actionPerformed(ActionEvent e) {
                        //do something here
                    }
                });
    
    
                if(popup.getComponentCount() > 0) {
                    popup.show(vv, e.getX(), e.getY());
                }
            }
    
        }
    }
    

    Add the class into an AbstractModalGraphMouse class which handles mouse listeners to make it work:

    private AbstractModalGraphMouse graphMouse;
    ...
    graphMouse = new DefaultModalGraphMouse<Object, Object>();
    vvMap.setGraphMouse(graphMouse);
    graphMouse.add(new PopupGraphMousePlugin());
    

    The codes above do work. But, if you use different user data for the generic parts, then you need to modify the codes to suit your design.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I want to create an application has this sort of function: http://looklet.com/create In
I want to display a pop up on each div click.the divs will create
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create module which update list of usb devices automatically (not only mass
I want to create a textbox which text binds an integer (e.g 123456789), but
I want to create 5 variables of type array all at once. Is this
How to create a pop up animation on iPhone? I want show my uiview
I am using the method from this question to create a pop-up to show
In Silverlight 3, I am trying to create a pop up menu for navigation.
My main frame contains JScrollPane which lists some objects. Through menu (pop up frame)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.