• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

draw rectangle in JPanel using mouse  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any one could please help me to give idea "how to draw a rectangle using mouse in Jpanel" and it should allow to draw more than one rectangle or other shapes.. if anyone have sample code please give it and help me... thanks in advance.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add a mouseListener to the panel
mousePressed get the x/y coords
mouseReleased get the x/y coords and repaint()
paintComponent() has graphics.drawRect(coords)
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not post the same message in multiple forums.

Thank you,

Layne
 
author and iconoclast
Posts: 24203
43
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please CarefullyChooseOneForum when posting at the Ranch. This question ought to have gone to the Swing Forum, where I'm moving it now.
[ January 10, 2006: Message edited by: Ernest Friedman-Hill ]
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!