使用面板消息/解决方法时Java 1.5 JOptionPane绘制错误? [英] Java 1.5 JOptionPane paint bug when using panel message/workaround?

查看:106
本文介绍了使用面板消息/解决方法时Java 1.5 JOptionPane绘制错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在针对Java 1.5的应用程序中,我有一个带有自定义消息面板的JOptionPane.该面板除其他外,还包含一个JTextField.每20次左右的调用,对话框中的任何内容都不会被绘制(甚至没有OK/Cancel按钮).如果我将对话框拖出屏幕,然后再次返回以强制重新绘制,则这些组件将按预期可见,并且除了绘画问题之外,这些组件的响应都很好.这是我可以展示此错误的最小示例:

I have a JOptionPane with a custom message panel in it, in an application targeted for Java 1.5. The panel contains, among other things, a JTextField. Every 20 invocations or so, nothing in the dialog gets painted (not even the OK/Cancel buttons). If I drag the dialog off the screen and back again to force a repaint, the components are visible as expected, and apart from the painting problem, the components respond fine. Here is the smallest example I could get to exhibit this bug:

public class BugTest {
  public static void main(String args[]) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        // The text field needs to be wrapped in a panel for the bug to show up.
        JPanel messagePanel = new JPanel();
        // A JLabel won't exhibit the bug, but a JTextField will.
        JTextField textField = new JTextField("Some content");
        messagePanel.add(textField);
        // Loop so we can keep clicking OK until the bug shows up.
        while (true) {
          int res = JOptionPane.showOptionDialog(null, messagePanel,
              "SomeTitle", JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.PLAIN_MESSAGE, null, null, null);
        }
      }
    });
  }
}

这是Swing中的一个著名错误吗?有标准的解决方法吗?我还没有为此找到官方的错误报告.该错误似乎未在Java 1.7中出现,但我的应用程序需要在较早的1.5上运行,我想找到一种在后者上可用的解决方法.

Is this a well-known bug in Swing? Is there a standard workaround? I haven't been able to find an official bug report for this. The bug does not appear to be present in Java 1.7, but my application needs to run on the older 1.5, and I'd like to find a workaround that works on the latter.

相关:无模式JDialog不显示内容(不包括代码示例,因此很难知道是否是相同的错误)

Related: Modeless JDialog not showing contents (does not include a code example, so it's hard to know if it's the same bug)

我发现该错误的特定Java版本是1.5.0_22.

The specific Java version I've found the bug on is 1.5.0_22.

推荐答案

此错误似乎可以在Java 1.5上重现,而在Windows Vista和XP(可能也在Win7上)上运行的Java 7上也可以.

This bug seems to be reporducible on Java 1.5 up to Java 7 running on Windows Vista and XP (probably also on Win7)

看看此错误报告(错误ID:6859086)

Take a look at this bug report (Bug ID: 6859086)

最可能的原因是GDI资源泄漏.看看 您可以使用以下任一方法跟踪Java进程消耗的GDI资源: 任务管理器或流程浏览器.

The most likely cause of the problem is a GDI resource leak. See if you could track GDI resources consumed by the java process with either task manager or process explorer.

根据错误报告,此解决方法不可用,但您可以尝试使用几个运行时选项:

According to the bug report the workaround is not available but you may try to play around with a couple of runtime options:

  • -Dswing.handleTopLevelPaint=false
  • -Dsun.java2d.d3d=true
  • -Dswing.handleTopLevelPaint=false
  • -Dsun.java2d.d3d=true

这篇关于使用面板消息/解决方法时Java 1.5 JOptionPane绘制错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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