Java 1.5 JOptionPane error when using panel / workaround message?

I have a JOptionPane with a custom message bar in an application designed for Java 1.5. The panel contains, among other things, JTextField. Every 20 prompts or so, nothing in the dialog box is colored (even the OK / Cancel buttons). If I dragged the dialog box from the screen and again to force it to redraw, the components will be visible as expected, and, apart from the painting problem, the components will respond normally. Here is the smallest example I could show in this error:

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); } } }); } } 

Is this a known bug in Swing? Is there a standard workaround? For this, I could not find the official error report. The error is not present in Java 1.7, but my application should work on an earlier 1.5, and I would like to find a workaround that works on the latter.

Related: Modeless JDialog does not show content (does not contain sample code, so it’s hard to know if it is the same error)

The specific version of Java on which I found the error is 1.5.0_22.

+4
source share
1 answer

This error seems to be reproducing in Java 1.5 to Java 7, running on Windows Vista and XP (possibly also on Win7)

Look in this error report (Error ID: 6859086)

The most likely cause of the problem is a GDI resource leak. You see, if you can track the GDI resources consumed by a java process using the task manager or the process explorer.

EDIT: According to the error message, the workaround is not available, but you can try playing around with several runtime options:

  • -Dswing.handleTopLevelPaint=false
  • -Dsun.java2d.d3d=true
+5
source

Source: https://habr.com/ru/post/1384778/


All Articles