-1

I would like to know how to pop up a JPopupMenu that shows up only in a specific range, for example between (200,300) and (400, 400).

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Mr. Liu
  • 337
  • 1
  • 3
  • 8
  • You mean, if the user clicks within the area defined by rectangle 200x300x400x400, you want a popup to show? – MadProgrammer Apr 10 '16 at 05:35
  • Yes! I have in a JPanel some rectangles and I want to pop up a menu only in those rectangles (not everywhere) so I can show up a menu and give the option to delete it or change the size. – Mr. Liu Apr 10 '16 at 05:44

1 Answers1

1
  • Create a java.awt.Rectangle of the desired size and position
  • Use a MouseListener to determine when the mouseClicked and mousePressed and mouseReleased event occurs, check to see if it's a popupTrigger
  • If it is a popup trigger, use the Rectangle to determine if it containts the MouseEvent
  • If that is all true, show the popup (at the point the MouseEvent occured

Have a look at How to Write a Mouse Listener and How to Use Menus for more details

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • Seriously? What part of this doesn't provide an answer to the OPs question? At least this way the OP has a point of reference from which to actually find the solutions to their own problems and maybe learn how to search for their own answers instead of posting more open questions – MadProgrammer Apr 11 '16 at 02:49
  • Forbid we actually "try" and help people :P – MadProgrammer Apr 11 '16 at 02:52