Results 1 to 2 of 2
  1. #1
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default Issue with TreeViewer and JPopupMenu and components in general

    So I'm trying to get the nodes in my treeViewer to open up a popup menu when I right click. The problem is since TreeViewer isn't a component I can't attach the menu to it so the menu won't show. My treeViewer has a mouse listener attached to it that correctly determines when and what I right click on and as far as I can tell it creates the popup menu,...it just can't display it.

    Java Code:
    treeViewer.getTree().addMouseListener(new MouseAdapter(){
       public void mouseUp(MouseEvent event) {
    	   if(event.button==3){
    		   if(selObj instanceof Server){
    			   JPopupMenu pMenu;
    			   JMenuItem menuItem;
    			   pMenu = new JPopupMenu();
    			   menuItem = new JMenuItem("Cut");
    			   pMenu.add(menuItem);
    			   menuItem = new JMenuItem("Copy");
    			   pMenu.add(menuItem);
    			   menuItem = new JMenuItem("Paste");
    			   pMenu.add(menuItem);
    					   
    			   System.out.println(pMenu.getInvoker());	//returns null
    		           System.out.println(pMenu.findComponentAt(event.x, event.y)); //returns null
    			   pMenu.show(pMenu.getInvoker(), event.x, event.y);				    
    		   
    		   
    			   System.out.println("Server Menu");
    			   //View Properties
    			   //Delete Server
    			   //Edit Server
    		   }			
    	   }
    	}
    });
    Should I be using something aside from JPopupMenu and JMenuItem to get this to work, or is there some work around your aware of that will let my menu show up attached to a composite(which is what TreeViewer is attached too) instead of Component?

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    So there seems to be a bug with TreeViewer and context menus. I can't find the actual bug report but the eclipse news feed mentions it here

    [news.eclipse.platform.swt] Alternative to Tree/Treeviewer

    Can anyone testify to the validity of this post? If it is true I need to quite wasting my time trying to make it work and spend it on rewriting my entire viewer without using JFace.

Similar Threads

  1. JPopupMenu
    By hungleon88 in forum NetBeans
    Replies: 8
    Last Post: 01-15-2009, 05:00 PM
  2. JPopupMenu problem
    By sylvievdb in forum AWT / Swing
    Replies: 3
    Last Post: 10-06-2008, 08:37 AM
  3. [SOLVED] General string problem in my database query.....?
    By prabhurangan in forum New To Java
    Replies: 7
    Last Post: 06-25-2008, 08:55 AM
  4. General Discussion on Abstract
    By sanjeevtarar in forum Advanced Java
    Replies: 15
    Last Post: 05-06-2008, 06:16 AM
  5. How to set General options in NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 08-02-2007, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •