The moose likes Swing / AWT / SWT / JFace and the fly likes Adding JComponent in Paint Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Adding JComponent in Paint" Watch "Adding JComponent in Paint" New topic
Author

Adding JComponent in Paint

Vijay Kashyap
Ranch Hand

Joined: Jul 30, 2001
Posts: 74
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

Joined: Jan 09, 2001
Posts: 1492
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

Joined: Jul 30, 2001
Posts: 74
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
 
 
subject: Adding JComponent in Paint
 
Threads others viewed
Add a JPanel to a JScrollPane
Question about a simple GUI application
JScrollPane
Graphics2D window not being repaired?
Problem converting applet to JApplet
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture