• Post Reply Bookmark Topic Watch Topic
  • New Topic

Canvas and JPanel

 
william brown
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to put a canvas in a JPanel so that I can do some drawing. The canvas must cover the entire space of the JPanel. Whenever I resize the JPanel, the canvas must also be resized.

I think I have to set the size (setSize) of the canvas. But I don't know how to get the size of the JPanel.

Or is there any other better way (on setting the size of the canvas) ?

Thank you.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where would you like the answer posted?

here, javaworld, any of the other places you cross-post to?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
where would you like the answer posted?

here, javaworld, any of the other places you cross-post to?


Cross-posting is quite alright so long as it's not the same message board. I often post the same question on 2-3 different boards. Then I get a better chance at getting a response.

William, why do you want to put a canvas on a JPanel? Why not simplify things and just draw on the JPanel. All you have to do is override the paintComponent method.
 
william brown
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. You are right Mr Gregg Bolinger. I just want to get more idea from the answers because I dont think everybody here are also in the other forums. Sorry if you dont feel happy with it, Mr Michael Dunn.

Thank you Mr Gregg Bolinger for your good idea. You have really helped me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!