permaculture playing cards
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

Canvas not displaying

ron noone

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!

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:
subject: Canvas not displaying
It's not a secret anymore!