首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止RootPane在GlassPane上重画

防止RootPane在GlassPane上重画
EN

Stack Overflow用户
提问于 2015-04-21 23:27:12
回答 1查看 80关注 0票数 1

这个问题类似于Paint on a glass pane without repainting other components。但我不知道如何应用那里提供的解决方案。

我的问题是,我们有一个非常复杂的RootPane,许多组件,重新绘制它是昂贵的。我们还在JFrame的GlassPane上运行了一个动画。我已经注意到,动画中的每一个滴答都在按其应有的方式重新绘制动画,但同时也会导致底层RootPane上的所有内容也被重新绘制。

我尝试用不同的代码重写RootPane的try ()方法,但是它总是会导致RootPane上的组件被擦除,并且有很多闪烁,可能是因为子组件试图在动画期间更新时重新绘制自己:

代码语言:javascript
复制
pnlContent = new JRootPane() {
   @Override
   public void paint(Graphics g) {
      OurGlassPaneWithAnimation glass = ...
      if (glass != null && glass.animation != null && glass.animation.isAlive()) {
         //Animation running, do something cool so root pane still looks good without repainting out the wazoo
      } else { super.paint(g); }
   }
};

也许把动画放进GlassPane是个坏主意?我们已经考虑过将其改为居中的JPanel。或者,是否有一种使用GlassPane并将重新绘制到后台RootPane的操作保持在最低限度的好方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-22 16:20:36

@MadProgrammer感谢你建议重新油漆(Rect)而不是仅仅重新油漆()解决了这个问题。现在,我们可以将动画up提高到我们想要的高度,并且它不会明显地影响后面的RootPane的加载时间。这是代码片段。

代码语言:javascript
复制
while (keepOnAnimating) {
   BufferedImage bi = vFrames.elementAt(0);
   if (bi != null) {
      // This only repaints area of image rect
      // Prevents lots of repaints from happening in rootpane behind glasspane.
      int x = getWidth() / 2 - bi.getWidth() / 2;
      int y = getHeight() / 2 - bi.getHeight() / 2;
      jc.repaint(x, y, bi.getWidth(), bi.getHeight());
  } else {
     jc.repaint();
  }
  ...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29784969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档