Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Jpanel paintcomponent

 
Gaurav Agarwal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic