gpt4 book ai didi

java - paint() 和 paintcomponent() 的区别?

转载 作者:搜寻专家 更新时间:2023-10-30 21:02:24 33 4
gpt4 key购买 nike

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

请尽量保持简单的答案,谢谢。

最佳答案

引用自 paint() 方法的文档

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()

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

关于java - paint() 和 paintcomponent() 的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15103553/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com