Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Add Graphics to Jpanel

 
Behrouz Hosseini
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
I just wondering how I can add a Graphics object like rectangle to a JPanel?
I have following classes and I can add the Label object into MyPanel but I cant add drawing object (MyRect) into Jpanel.I know that I am not constructing any thing in MyRect() constructor! so it make sence for me that nothing will happen in MyPanel when I call for MyRect constructor but I don't' know how to call the paintComponent with it's parameters in MyPanel class!
Could you please let me know is it possible to add a drawing into a panel?
so what's wrong with this code?



Best Regards,
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
debugging 101:

after adding/displaying, print out the panel's size
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic