Java TextArea 绘制方法在哪里实现?
我正在寻找 Java TextArea
组件的 paint
方法实现(java.awt.TextArea)。
我已经阅读了该类及其超类的源代码(java.awt.TextComponent),但还没有找到 public void Paint(Graphics g)
方法实现,我认为这是意味着该类将使用默认的 Component#paint(Graphics) 实现,这是没有意义的。我在这里错过了什么吗? TextArea
组件是如何绘制的?
I am looking for the paint
method implementation for a Java TextArea
component (java.awt.TextArea).
I have read through the source code for the class as well as its super class (java.awt.TextComponent), but have not found a public void paint(Graphics g)
method implementation, which I think means the class would be using the default Component#paint(Graphics)
implementation, which doesn't make sense. Am I missing something here? How is a TextArea
component painted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TextArea 是一个 AWT 组件,而不是 Swing 组件。因此,它是所谓的重量级组件,这意味着它实际上是由底层平台/操作系统的本机组件(即 Windows/Gnome/Motif 组件,取决于操作系统)(称为组件的对等体)实现的。因此,绘画是由平台的本机小部件完成的,而不是由组件完成的。
TextArea is an AWT component, not a Swing component. It's thus what's called a heavyweight component, which means it's in fact implemented by a native component of the underlying platform/OS (i.e. a Windows/Gnome/Motif component, depending on the OS), called the peer of the component. The painting is thus done by the platform's native widget, and not by the component.
AWT 组件
是上个世纪的恐龙,只有通过向后兼容
才存在并且仍然存在,请/最好将其更改为今天的 JComponents< /code>,全部以“J”开头,这里是 JComponents 带有教程,但是对于 Swing 的 JComponents 来说,有
paintComponent(Graphics g)
而不是paint(Graphics g)
方法 Paint 仍然存在,但是对于XxxXxxUI中最深的绘画,例如MetalButtonUI,但不适用于绘制图像/线条/文本...并且只是尽量避免 2000 年的类似示例 和另一个非常古老的示例,这对于 Java6 的 Swing 中的自定义绘画来说确实是错误的实现,
这是您所需的 教程 和 Java6 API
在这个论坛上有很多关于
Painting Something in JComponents
的帖子编辑:如果你想画一些东西,那么寻找 JLabel (默认透明),最好的
JComponent
对于 2D 图形,该示例 此处,并使用paintComponent()方法仅有的AWT Components
is dinosauruses from last milenium, and only byback-compactible
are there and still exists, please/better would be to change that to theTodays JComponents
, all starts with "J" here is list of JComponents with tutorials, but for Swing's JComponents is therepaintComponent(Graphics g)
instead ofpaint(Graphics g)
method paint is still there but for deepest painting in XxxXxxUI, for example MetalButtonUI, but not for painting Image/Lines/Text ... and just try to avoid a similar examples from year 2000 and another very old examples, that's really wrong implemntation for Custom Painting in Java6's Swing,
here is your required tutorial and Java6 API
on this Forum are plenty threads about
Painting Something in JComponents
EDIT: if you want to paint something then look for JLabel (is transparent by defalut), that best
JComponent
for 2D Graphics, examples for that here, and with paintComponent() method only