paint()和paintcomponent()之间的区别? [英] Difference between paint() and paintcomponent()?

查看:99
本文介绍了paint()和paintcomponent()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过这方面的教程,但我仍然不太明白。基本上我的问题是哪种方法更好,为什么?我应该使用 paint 还是 paintComponent

I have tried tutorials on this but I still don't quite understand it. Basically my question is which method is better and why? Should I use paint or paintComponent?

请尝试保持答案简单,谢谢。

Please try to keep the answer simple, thanks.

推荐答案

引用 paint()的文档方法


此方法实际上将绘画工作委托给三个受保护的方法:paintComponent,paintBorder和paintChildren。
...
只想专门化UI(外观)委托的paint方法的子类应该覆盖paintComponent。

This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. ... A subclass that just wants to specialize the UI (look and feel) delegate's paint method should just override paintComponent.

看起来 paint()方法实际上绘制了组件,包括边框和子项。如果您只想自定义除边框和子项之外的组件外观,则使用 paintComponent()

It looks like the paint() method actually draws the component, including the border and children. If you only want to customize the component's appearance excluding the border and children, you use paintComponent().

< a href =http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#paint(java.awt.Graphics)> http://docs.oracle.com/ javase / 7 / docs / api / javax / swing / JComponent.html #paint(java.awt.Graphics)

这篇关于paint()和paintcomponent()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆