aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes add a Canvas to a JPanel within a JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "add a Canvas to a JPanel within a JFrame" Watch "add a Canvas to a JPanel within a JFrame" New topic
Author

add a Canvas to a JPanel within a JFrame

samifox
Greenhorn

Joined: Sep 03, 2001
Posts: 5
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

Joined: Sep 29, 2000
Posts: 8521
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.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1

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.


Sun Certified Programmer for the Java 2 Platform
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Remove the call to super in the paint method and the string gets drawn. I didn't see the image though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: add a Canvas to a JPanel within a JFrame