• Post Reply Bookmark Topic Watch Topic
  • New Topic

drag rect  RSS feed

 
dejie lin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
if i draw a rectanglar in a panel, how can i drag it to anywhere in the panel?
anybody can give me some similar examples about this feature to dealing with graphics??
thanks in advance
dejie
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would attach a MouseMotionListener to the panel, and in the mouseDragged() method you would update the rectangle's x and y values.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!