Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Canvas not displaying

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't call setVisible until you finish adding your components to the contentPane.
a wee bit from the empire
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic