How to display right-click menu for JPanel?

Hi...
I am developing an application to display a JWindow in the screen along with a TrayIcon in the system-tray area. There should be a right-click menu in both the tray icon and JWindow for further options.
I am able to create a JPopupMenu for tray icon. On right-clicking on the tray icon, the menu is being displayed. But not able to do the same for the JWindow. I am able to capture the right-click mouse event, but not able to display the menu.
This is how I am displaying the menu for the tray icon
PopupMenu  popupmenu = new PopupMenu();
MenuItem  menuitem1 = new MenuItem("Exit");
menuitem1.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent exx)
        System.exit(0);
popupmenu.add(menuitem1);
trayicon = new TrayIcon(Toolkit.getDefaultToolkit().getImage("./images/Icon.gif"),"Right-click for more options",popupmenu);For displaying the menu in the JPanel, I am using the following snippet...
    public class MyMouseListener extends MouseAdapter
        public class MyMouseListener() {}
        @Override
        public void mouseClicked(MouseEvent e)
            if (e.getButton() == MouseEvent.BUTTON3)
               System.out.println("Clicked");
               jp.setComponentPopupMenu(popupmenu);
    }Can anyone please help me to do this??
Thanks in Advance...

Hi,
PFA the code I am using...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DisplayStrip extends JWindow implements MouseListener, MouseMotionListener
     Point location;
     MouseEvent pressed;
    JPanel jp ;
    JLabel jl ;
    JPopupMenu popupmenu ;
     public DisplayStrip()
          addMouseListener( this );
          addMouseMotionListener( this );
     public void mousePressed(MouseEvent me)
          pressed = me;
     public void mouseClicked(MouseEvent e) {}
     public void mouseReleased(MouseEvent e) {}
     public void mouseDragged(MouseEvent me)
          location = getLocation(location);
          int x = location.x - pressed.getX() + me.getX();
          int y = location.y - pressed.getY() + me.getY();
          setLocation(x, y);
     public void mouseMoved(MouseEvent e) {}
     public void mouseEntered(MouseEvent e) {}
     public void mouseExited(MouseEvent e) {}
     public void DisplayStripRun()
          setSize(100, 10);
          setAlwaysOnTop(true);
        jp = new JPanel();
          jp.setBackground(Color.GREEN);
          jp.addMouseListener(new MyMouseListener());
          jl = new JLabel();
          jl.setText("Right-click Here");
          jp.add(jl);
          add(jp);
          setVisible(true);
          pack();
          popupmenu = new JPopupMenu();
          JMenuItem menuitem = new JMenuItem("Exit");
          menuitem.addActionListener(new ActionListener()
               public void actionPerformed(ActionEvent exx)
                    System.exit(0);
          popupmenu.add(menuitem);
     public static void main(String args[])
          DisplayStrip ds = new DisplayStrip();
          ds.DisplayStripRun();
    public class MyMouseListener extends MouseAdapter
        //public class MyMouseListener() {}
        @Override
        public void mouseClicked(MouseEvent e)
            if (e.getButton() == MouseEvent.BUTTON3)
               System.out.println("Right clicked");
               jp.setComponentPopupMenu(popupmenu);
               popupmenu.setVisible(true);
}

Similar Messages

  • How to display a seperate right click menu for each item of a tree control?

    Hi I want to display a specific right click menu when a particular tree item is selected. I know how to create a menu and how to display it. I am using the function GetLabelFromIndex() to get the active tree item and then compare the label and based on the result display a manu for that item. Now my problem is that when I use the above function in the EVENT_RIGHT_CLICK it gives me the error "the Index passed is out of range" while using the same function with the same arguments in EVENT_SELECTION_CHANGE it gives no error...below is the part of my code
    case EVENT_RIGHT_CLICK:
    GetLabelFromIndex(panelHandle, PANEL_TREE, eventData2, label1);
    //The function gives the stated error here
    if(eventData1)//after it I compare the result and display the menu
    case EVENT_SELECTION_CHANGE:
    GetLabelFromIndex (panelHandle, PANEL_TREE, eventData2, label1);
    //The function works fine here
    if (eventData1)
     If any one have any idea whats going on or alternate way of doing this Please share knowledge...Thanks
    If you are young work to Learn, not to earn.

    Hi,
    one possible approach of solving this problem is looking closer at the error message: The error "the Index passed is out of range" tells you that something is wrong with the index, either it is too small or too large So why don't you set a breakpoint and check the index value, it might be useful information...
    The other hint is to check the meaning of eventdata2 (using the help): It is different for different events! For the event_right_click it gives the horizontal mouse position, not the index as event_selection_change does...

  • How do I make a feature request for Firefox? Need for "Keep this website" in right-click menu for History viewing.

    During my daily Firefox sessions (w/over 300 RSS feeds), I commonly visit about 50 web sites. At the end of a session I may only want to keep one or a few history entries and have to manually delete the rest. I always keep one in particular.
    It would be infinitely easier if the capability of "Keep this Site" option were available in the right-click menu which would mean deleting the remainder of the history entries not marked to be kept, in conjunction with the History delete options in Firefox Preferences.
    Note: This is a real User need I have, and possibly many others would like the versatility.

    You can click the star in the location bar to bookmark a site that you want to keep.
    *https://support.mozilla.com/kb/how-do-i-use-bookmarks

  • Does "Distribute content" on the right click menu for a OSD Task sequence also REDISTRIBUTE packages?

    I have a task sequence with quite a few packages that have already been distributed. But that same task sequence has far more that have never been distributed.
    When you Right click a SCCM OSD Task sequence and select "Distribute Content", does it also redistribute content that's already been distributed to existing DP's, or just the packages that have never been distributed?

    Hi,
    You can only select DP's that don't have the Packages required by the Task Seqeunce so no you cannot use it to update the DP's
    Regards,
    Jörgen
    -- My System Center blog ccmexec.com -- Twitter
    @ccmexec

  • How do i right click on a jpanel and make a menu come up where i clicked

    basically i want to allow the user to click on screen and a menu popup where they clciked which has a list of options such as A,B,C.
    I think you have to use a menuBar method or something. im not 2 sure
    anyone have some quick code.

    when the mouse is pressed, mousePressed method is called. Something like this in that method should be put.
    pubic void mousePressed (MouseEvent e)
          if (e.getButton() == MouseEvent.BUTTON3) // Block for triggering popup
                JPopupMenu menu = new JPopupMenu ();
                menu.add (new JMenuItem (....));
                menu.show ([put the jpanel name here], e.getX(), e.getY());
    }Edited by: Cricket_struck on Feb 1, 2009 5:08 PM

  • Removing "Open With [Program]" from Right-Click menu

    I was looking around for Applications that could play .avi files and I found Perian  so decided to install it. After installing it I quickly found that it didn't work with all of my .avi files and after some further reading realized that Perian is no longer supported and apparently does not work with QT 10. I decided to uninstall it and use VLC player instead. After uninstalling Perian and removing it from the "System Properties" it looks like it's still showing up in the right-click menu for .avi files.
    My question is how do I remove this from being an option whenever I right-click an .avi file? Perian is no longer installed and I don't want to see it as an option.
    Thanks in advance

    This is probably because all the associated files have not been removed and it is still in the LaunchServices cache. To be sure you remove all associated files may require re-installing the app and using AppCleaner  to trash it and it's supporting files.
    Then, you may also need to clear LaunchServices caches
    Launch /Utilities/Terminal and copy & paste this at the prompt to rebuild LaunchServices: (be sure to copy the entire line it's a scroll)
    Code:
    /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
    Then press return. Wait until terminal returns to the command line. Quit Terminal. After that, log out and back in or restart. Let us know

  • Is there any way of removing the browser buttons from the right click menu?

    Recently when I right-click on a web page, there are browser buttons (forward, backward, refresh, bookmarks) on the right-click menu for some inexplicable reason. I mean, its kind of absurd that anyone would put browser buttons there, considering the real browser buttons literally right there at the top of the window, and I guess that kinda bugs me.
    Anyway, how did I get rid of them? There doesn't seem to be any way to do so in the customize window, and I've been looking for an add-on but don't really know what to search for. Does anyone know?
    Where did those come from anyway? They weren't there a week ago, and I'm pretty sure these things don't normally just pop up out of nowhere. If nobody knows, its really not important. The important thing is getting rid of them. Thanks!

    That was a new feature in Firefox 32, which was released back in September. Use this UserStyle to get rid of those buttons and restore the text menu items.
    https://userstyles.org/styles/104945/fx-32-context-menu-full-text
    ''You'll need the Stylish extension to be able to install UserStyles.''
    https://addons.mozilla.org/en-US/firefox/addon/stylish/

  • Data Grid Right click menu customize

    Hi All,
    i need to change the data grid right click menu customize the background color,background mouse over color, Text color, Text hover color . can any one help me this
    Regards
    Rajesh

    cat14 wrote:
    > Any idea on how to customize right click menu?
    > I've seen some site could show the company name.
    >
    > Pls advice.
    You can check Help for "ContextMenu" to get details info,
    meantime
    simple example of getting a link to author's site:
    var my_cm:ContextMenu = new ContextMenu();
    var menuItem_cmi:ContextMenuItem = new ContextMenuItem("Made
    by Yahoo", onSelection);
    my_cm.customItems.push(menuItem_cmi);
    function onSelection(obj, menuItem) {
    trace("You just selected " + menuItem.caption);
    getURL("
    http://www.yahoo.com", "_blank");
    this.menu = my_cm;
    Best Regards
    Urami
    <urami>
    If you want to mail me - DO NOT LAUGH AT MY ADDRESS
    </urami>

  • How to display images for right click menu items

    I am trying to display some image to the left of my right click menu items.I have searched the help but did't find anything wich can add an image to the menu items. If anyone knows how to do it, Please share 
    Thank to all.
    If you are young work to Learn, not to earn.

    Hi Mr,
    you should have searched the topic 'Programming with Menu Bars'
    Use the ATTR_SHOW_IMAGES attribute to add a column in the menu in which images can be placed. Then use the ATTR_ITEM_BITMAP attribute to specify an image to use for a submenu or menu item

  • How to remove the option "Set as default background..." from the right-click menu on a picture, for all users.

    Hi! I would like to know if there is any possibility to remove the option "Set as default background..." from the right-click menu on a picture, for all users. I know that's possible to edit userContent.css or userChrome.css, but this concerns only a profile at a time and being in a domain, I would like to set this for all people using Firefox.
    Can it be possible to edit a mozilla.cfg file to get the same result?
    Thank you in advance for help and tips.

    AFAIK then there is no way to do that system wide. You can only do that via userChrome.css or an extension like the Menu Editor per profile .You can install extensions globally, but the user will have to enable them anyway. That is not required for userChrome.css code.

  • How to get rid of right click menu?

    I like to mouse over a hyperlink in a web page and select "open in a new tab". The right click menu jumps in the way. I don't like or use the right click menu. How do I stop it from stopping me? As a side note, the reason I like "open in a new tab" is that some websites will open on the same page and in some events the back button will not return you to that page. I find the new tab very helpful and the right click menu a pain in the ---.
    Win 8.1
    Firefox - newest
    Alternatively, is there a way to add "open in a new tab" to the menu that gets in the way?
    I was trying to open "Sign Up/Sign In" in a new tab.
    Completely irrelevant to my question, but since you see my tabs, I was watching Jon Stewart on Hulu. He was raving about the Katy Perry Superbowl show. I wanted to see what he was talking about. I don't give a flying crap in the rain about the Stupor Bowl.

    The right-click menu is context-sensitive. When you right-click a link, you should have the option to open in a new tab, new window, or new private window. (In a private window, "new window" is not displayed.) The menu in your screen shot would normally appear if you clicked a blank area of the page without a link directly under the mouse pointer.
    I can't think of any built-in way to get the Open in New Tab command just mousing over a hyperlink. Do you have an add-on that does that automatically for you? If so, I wonder whether it might need an update?

  • How do I add entries to PCManFM's right-click menu? [SOLVED]

    Hello there,
    Is there a way to customize PCManFM right-click menu? I'd like to add custom entries, for instance:
    right click a folder and choose "Start slideshow" to get the following command executed: "qiv -smt <selected_folder>"
    Can this be done? How?
    This could be a system-wide setting or a user setting, I don't really care.
    Thanks for any guidance.
    Last edited by brazzmonkey (2009-03-16 20:42:36)

    Inxsible wrote:Yup that's what I am doing, but on selecting an app from the All Applications tab, it creates a .desktop file in my home folder under the .local folder. The next time you try to go into the Open With menu, Geany (or any other app - that I selected from the All Applications list) shows up twice.
    Well , I'm not sure what's the problem here . I only see this when I attach a media player(e.g mplayer) to different file formats . PcManFM seems to insist on creating a .desktop file for each association but I don't see duplicate entries in the menu .
    ~/.local/share/applications$ ls | grep mplayer
    mplayer-usercreated-1-usercustom-0.desktop
    mplayer-usercreated-1-usercustom-1.desktop
    mplayer-usercreated-1-usercustom-2.desktop
    mplayer-usercreated-1-usercustom-3-usercustom-0-usercustom-0.desktop
    mplayer-usercreated-1-usercustom-3-usercustom-0.desktop
    mplayer-usercreated-1-usercustom-3.desktop
    mplayer-usercreated-1.desktop
    smplayer-usercustom-0-usercustom-0-usercustom-0-usercustom-0.desktop
    smplayer-usercustom-0-usercustom-0-usercustom-0-usercustom-1.desktop
    smplayer-usercustom-0-usercustom-0-usercustom-0.desktop
    Last edited by Nezmer (2009-03-16 22:50:28)

  • HT201403 It would be very helpful for Apple to re-instate the view as icon option for a pdf file in an email on the right click menu? As far as I can see no easy way for a basic user to get this back?

    Would be great for Apple to reinstate the pdf as icon in mail - but using the right click menu. It seems to have gone - and as a basic user there seems to be no simple solution - I used the rich/plain text swap but it didn't work...
    Apple - we need you to solve!

    http://www.apple.com/feedback/macosx.html
    It's highly doubtful that Apple will change this in Mac OS X 10.7 since that OS version has now been discontinued for quite some time. Whether they will change that in OS X 10.9 or a future version I can't say.
    If this is a serious issue for you, you can look into Attachement Tamer:
    http://lokiware.info/Attachment-Tamer
    It's not free, but it addresses much more than the issue of PDFs appearing as images, not icons, so it might be worth the price.
    Regards.

  • How can I add custom right-click-menu to column headers in JTable?

    Can anyone point me to a topic on how to customize a popup menu for column headers in JTable? Specifically, I want to add things like "auto-size column" and "hide column".
    Thanks,
    Matt

    Right-click on your table.  Then go to Advanced->Runtime Shortcut Menu->Edit.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • I was on facebook and deleted an icon by using the right-click menu but then all my pictures and all profile pictures, could no longer be seen. I was able to view them in Explorer so this is something I did in Firefox. How can I unblock a site?'

    '''I was on facebook and deleted an icon by using the right-click menu but then all my pictures and all profile pictures, could no longer be seen. I was able to view them in Explorer so this is something I did in Firefox. How can I unblock a site?'''

    If you select that right-click context menu entry then you block all images from that domain and not one specific image, so do not use that.
    * Check the exceptions in Tools > Options > Content: Load Images > Exceptions (e.g. sphotos.ak.fbcdn.net)
    You can use these steps to check if images are blocked:
    * Open the web page that has the images missing in a browser tab.
    * Click the website favicon ([[Site Identity Button]]) on the left end of the location bar.
    * Click the "More Information" button to open the "Page Info" window with the Security tab selected (also accessible via "Tools > Page Info").
    * Go to the <i>Media</i> tab of the "Tools > Page Info" window.
    * Select the first image link and scroll down through the list with the Down arrow key.
    * If an image in the list is grayed and there is a check-mark in the box "<i>Block Images from...</i>" then remove that mark to unblock the images from that domain.

Maybe you are looking for

  • Clearing date for the payment invoice through APP

    Hi All, I have some payment invoice which falls net due date on sunday so i can't able to run app on sunday(holiday)  so i use to run on saturday for getting the discount before the net due date.  While paying like this the system is taking clearing

  • My iPod crashes frequently

    Hi. I've got the following problem: Every once in a while my iPod (with colour display) goes black and won't restart until I connect it to a power source. I tried resetting it and updating the firmware, but it still happens. Does anyone have any idea

  • SIM Cards from other countries

    I want to buy an iPad 2 Wi-Fi + 3G whilst in the USA. I travel to Europe and south America and I have SIM's for Argentina, Sweden, Spain and London, as well as other countries. I want to use these in iPad 2. Is it possible and how can this be done. A

  • Displaying Large Blocks of Text with Flex for Mobile

    Hi, I have prepared an application for Android in Adobe Flash Builder. In application there are prayers in Arabic as a list. In app , short prayers are displaying quickly, but long prayers are displaying  after a long time. This is my problem. I shar

  • Windows XP can't see my Airport Extreme

    Was given an airport extreme to replace my old d-link wireless router, which stereotypically died. I have a D-Link Airplus G+ wireless card, and cannot fathom how to make my computer see the airport. Airport is plugged into broadband, it's green ligh