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

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

问题描述

我已经尝试了这方面的教程,但我仍然不太明白.基本上我的问题是哪种方法更好,为什么?我应该使用 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(外观和感觉)委托的绘制方法的子类应该只覆盖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().

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

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

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