• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

add a Canvas to a JPanel within a JFrame

 
samifox
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there!
i extends Canvas and i draw image in it like this :

th problem is when i try to put the class instance on a JFrame and user add() , the Canvas doesnt appear ,
this is how i test it :

thanks in advance
Shay



[This message has been edited by samifox (edited September 03, 2001).]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please change your name to be compliant with JavaRanch's naming policy.
Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
Thanks,
Cindy
I am moving this thread to the AWT/Swing forum.
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You need to do two things (I think):
- Use a layout managerin your Frame; e.g. GridLayout(1,1)
- implement getPreferredSize() in your Canvas so that the layout manager knows how big it should be.
Note this is based on AWT. I don't know if Swing works exactly the same way.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the call to super in the paint method and the string gets drawn. I didn't see the image though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic