wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes About Jpanel paintcomponent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "About Jpanel paintcomponent" Watch "About Jpanel paintcomponent" New topic
Author

About Jpanel paintcomponent

Gaurav Agarwal
Greenhorn

Joined: Oct 13, 2004
Posts: 18
hello all
I am try to display the graphics elements like line with the button component and I choose to display that in Panel using paintComponent But It is display that two time and It is not working properly.

could any one tell me what to do in that case and there is any mecanism to get the graphics object instead of using paintcomponent() fuction because i think that the problem is occuring with that function.


Thanks in advance
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
You can use the JComponent method getGraphics to get a reference to the graphics context. What you draw with it will not survive past the next system–triggered repainting episode. For persistence, it is recommended that you do all drawing from within the paintComponent method for JComponents.

You mentioned Panel which is an AWT component. For AWT components you use the paint method. It is recommended that we not mix Swing and AWT components.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About Jpanel paintcomponent