This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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