• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

PopUp Menu for JTree

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have a Jtree which on right click will show a pop up menu.

The problem is when i select any node in the tree with a left click and the right click anywhere in the frame that holds the JTree the pop up menu is Displayed.
I Want to display this pop up menu only when i right click on the selected Node in the JTree.

What am i to do to make this pop up work as intended ??


Thanks in Advance...
 
Author
Posts: 976
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sakthi anandan wrote:
right click anywhere in the frame that holds the JTree the pop up menu is Displayed.



Anywhere in the frame? Or do you mean anywhere within the tree's scroll pane?


I Want to display this pop up menu only when i right click on the selected Node in the JTree.

What am i to do to make this pop up work as intended ??



What you do is examine the mouse event to get the x and y coordinates,
then use tree methods to make sure the click was actually over your node.

Consider:
  • MouseEvent.getPoint()
  • JTree.getClosestPathForLocation()
  • JTree.getPathBounds().contains() // but watch out for null
  • TreePath.getLastPathComponent()
  • etc.


  •  
    sakthi anandan
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The pop up appears when right clicked anywhere in the scroll pane containing the JTree.


    I am able to make the pop up appear only when right clicked on the node by using the mouseevent getx(), gety() and the components bound.
    But i want to know if there are any alternative way for doing the same.
     
    sakthi anandan
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    can somebody help me with this
     
    I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
    Free, earth friendly heat - from the CodeRanch trailboss
    https://www.kickstarter.com/projects/paulwheaton/free-heat
    reply
      Bookmark Topic Watch Topic
    • New Topic