Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding JComponent in Paint  RSS feed

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am stuck up a bit while adding a JComponent in paint method of my JPanel. I am using graphics to add lines (a kinda chart) to the JPanel. At one particular location I have to add my JComponent. Can I simply add it by calling JPanel.add(my component) on the parent JPanel ? Well I am doing exactly the same but with no effects what so ever. I am not able to make JComponent appear along with all other lines.
Could any body please help me out. Also please do tell me whether I can add a swing component this way.
Regards,
Vijay
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vijay,
You might want to rethink your design. The paint method gets called a lot (expose, first time, resize, etc) and you should not be adding any components in it because you will end up with many components when you only want one! You should only use the paint method for drawing your lines.
Regards,
Manfred.
 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manfred,
Thanks for replying. Sorry for putting it wrongly, I am just changing the location of JComponent in paint method. I am able to resolve the problem , it has to do with not calling super.paint , now everything seems to be owrking fine.
Cheers,
Vijay
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!