Java中的repaint()方法 [英] repaint() Method in Java

查看:245
本文介绍了Java中的repaint()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Java图形类,我只是想知道-什么时候需要调用方法repaint()?我尝试将其注释掉,但它似乎并没有影响我的输出GUI.不过,我已经看到它在我阅读的Java GUI代码中使用了很多内容.有人介意解释何时使用和何时不使用它吗?

I am playing around with the Java graphics class a little bit and I was just wondering--when is it necessary to call the method repaint()? I tried commenting it out and it didn't seem to affect my output GUI. I've seen it used a lot in Java GUI code that I've read, though. Would anyone mind explaining when to use it and when not to use it?

推荐答案

在大多数swing应用程序中,它从来没有真正必要,因为它们是自动处理的(对于常见的操作,例如更改按钮上的文本值并将数据添加到列表框)

It's never really necessary in most swing applications, because they handle it automatically (for common operations such as changing text values on buttons and adding data to a list box).

通常,只有进行了某些更改后,摆动才会自动发生-例如,您没有使用布局管理器,而是手动调整了组件的大小(因为通常情况下,布局管理器会重新绘制其组件的颜色必要时.)

Generally, it's only if you've made some sort of change that swing won't automatically pick up - for example, you're not using a layout manager and are resizing components manually (because normally the layout manager repaints its components when necessary).

这篇关于Java中的repaint()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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