• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Popup Menu

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

I have a JTable, and if a user "right clicks" on a row, a pop up menu should come up.

This is so far what I have done, but its not working correctly.




The pop up menu does come up when I "right click", however the screen of the table disappears and the
popup menu comes up on the corner of the screen, i want it to be where the user "right clicks"

Your help will be greatly appreciated

Pranay
 
Sheriff
Posts: 22684
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pranay Narotam wrote:


Please use MouseEvent.BUTTON3; it will make reading a bit easier, and if Sun decides to change its value from 3 to something else like -3, your code will still work.


You're using a BorderLayout, which allows only one component at its center. By using add(jpMenu) you are replacing the table with the popup menu.

This also isn't the way popup menus work. They should not get added to an existing control; instead, they have their own window which you can show as follows:
Combined with your mouse listener:
 
Pranay Narotam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks alot, It works perfectly



Pranay
 
Pranay Narotam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again

I am looking at the code, it works perfectly but i don't seem to understand why there is a parameter "COMPONENT" in the method


Thanks again

Pranay
 
Rob Spoor
Sheriff
Posts: 22684
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to show the popup for a specific component. I've decided to get that from the mouse event, but you can hard code it to be your table as well of course. In that case, you can remove the entire parameter:
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic