File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Canvas not displaying Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Canvas not displaying" Watch "Canvas not displaying" New topic
Author

Canvas not displaying

ron noone
Greenhorn

Joined: Mar 09, 2006
Posts: 1
Hello, I have a small problem with a program im working on.
I have a class that extends JFrame and in that class I have an inner class of type Canvas whose paint method I have overridden.
Here is the problem..
When I start my program the canvas does not display the image I have drawn on it. If I resize the JFrame that the Canvas is in, it will instantly display it. Unless I resize it, it never shows the drawing. The paint and repaint calls do work since after I do this resizing of the window, I can use my program. Any idea's?
In my class extending JFrame I have this code..


In my first lines of the run() method of the class I retrieve my data and call the repaint method. Obviously the repaint and paint work...the canvas just isnt 'active'. Also, I setup a MouseAdapter and anytime I click the mouse button on the canvas is outputs a line to the System console. When I first start the program and the canvas doesnt display the drawing, no matter how many times I click it will not recognize the mouse click, but like I said earlier once I resize the main window it will recognize it, as well as paint display the drawing.

Any idea's?
Sounds like something simple I've overlooked.

Thanks in advance!

Ron
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Don't call setVisible until you finish adding your components to the contentPane.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Canvas not displaying
 
Similar Threads
I can't figure out why this is not working!
How to avoid repaint?
strange problem
Having two problem on paint
how to keep drawn free hand painted image when resizing the window