Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Canvas appears in JFrame but not JPanel

 
Liz Costelloe
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm using a canvas to draw a very simple picture, retangle and a few circles in an Applet. The canvas is in a JPanel, inside a JTabbedPane. When I put the canvas in a JFrame, there is no problem it pops up and all the content is in place. However when I put the same JTabbedPane in a JPanel so it is embedded in a JSP the content does not appear at all.

I've done some debugging and it seems the paint() method for the Canvas is not being invoked at all. I've used repaint(), validate() and paint(canvasInstance.getGraphics()). I think it might be that the Graphics object used in the paint() method is returning null.

I've also tried overwriting the paint method of a JPanel - will this work??

I'd be very grateful for any suggestions/ideas.

Many thanks!

[ April 12, 2006: Message edited by: Liz Costelloe ]

[ April 12, 2006: Message edited by: Liz Costelloe ]
[ April 12, 2006: Message edited by: Liz Costelloe ]
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Swing you should generally not override the paint method, but the paintComponents method. In which applet method do you create the GUI - init or start?
 
Liz Costelloe
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Apologies for this delay responding. I will bear that in mind that I should be over-riding the paintComponents method, thanks.

Also, to answer your question, I use the init method to create the GUI - I assume this must have some impact so I'll head off and do some reading around this now!

Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic