• Post Reply Bookmark Topic Watch Topic
  • New Topic

Popup Menu  RSS feed

 
Pranay Narotam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi

Thanks alot, It works perfectly



Pranay
 
Pranay Narotam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!