Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Canvas not displaying

 
ron noone
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't call setVisible until you finish adding your components to the contentPane.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic