Java custom drawing with paintComponent() and paint()

☆樱花仙子☆ 提交于 2021-02-05 10:39:53

问题


I come from an Objective-C background and I have been developing on the iOS and Mac OS platform for a number of years now. I love the concept of custom drawing and therefore I would like to replicate what had been done by me on the aforementioned platform.

In iOS I would call -drawRect() to draw a custom view and then, I could go ahead and add other visual components on top of that drawing. I know that there are equivalents in java swing and awt called paint() and paintComponent(). However, I am not quite sure how the drawing goes about. I do not know when to call the super method (beginning or end ?) and how to add other components to the custom drawn component (custom drawing sometimes appears on top, sometimes beneath).

Can someone shed some light on this ?

I have already read up a little bit on when to use what, but I am still not 100% sure, so can anybody explain when exactly to use paint() and when paintComponent() ?


回答1:


Start with the java tutorials.

http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html



来源:https://stackoverflow.com/questions/20335814/java-custom-drawing-with-paintcomponent-and-paint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!