(!!!急)如何部分重绘 Java Swing Panel

martinfei 2008-04-21 10:14:22
在Swing Panel当中,通常情况下要重载paintComponent方法来重绘Panel上面的内容。 现在遇到一个特殊情况,我想让Panel在 mouseMoved事件当中重绘Panel的部分区域。由于绘制整个Panel的代价比较大,如果刷新整个Panel,界面会闪烁的特别严重而且CPU资源损耗严重,所以,我想只重绘Panel的特定部分。我试过两种方法,1)不通过paintComponent来重绘,而是另外写一个方法来完成。结果可想而之是Panel根本不能重绘。2)通过paintComponent来重绘,在paintComponent方法当中,用标志位来判断只做部分重绘。结果Panel其他部分空白,这是因为程序没有重绘其他部分。

请教高手,如何让Java Swing Panel一部分重绘,同时还要显示其他部分。 万分感激!!
...全文
1296 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangznyi1 2010-05-12
  • 打赏
  • 举报
回复
学习学习
dracularking 2008-04-22
  • 打赏
  • 举报
回复
也可用setClip方法

public abstract void setClip(int x,
int y,
int width,
int height)
Sets the current clip to the rectangle specified by the given coordinates. This method sets the user clip, which is independent of the clipping associated with device bounds and window visibility. Rendering operations have no effect outside of the clipping area.
hmsuccess 2008-04-22
  • 打赏
  • 举报
回复
参考:http://topic.csdn.net/u/20080315/22/c4277753-613d-48e4-9b46-27bebe8d8000.html
qusic 2008-04-22
  • 打赏
  • 举报
回复
void repaint(int x, int y, int width, int height)
重绘组件的指定矩形区域。

void repaint(long tm, int x, int y, int width, int height)
在 tm 毫秒内重绘组件的指定矩形区域。
看看这两个方法!是Component类中的
Inhibitory 2008-04-21
  • 打赏
  • 举报
回复
在paintComponent中的第一句调用super.paintComponent(g);
haode 2008-04-21
  • 打赏
  • 举报
回复
特定部分放一个小控件,重绘之

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧