United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6963024 Only Applets on Windows: two JOptionPanes in a row makes the 2nd JOptionPane flicker
JDK-6963024 : Only Applets on Windows: two JOptionPanes in a row makes the 2nd JOptionPane flicker

Details
Type:
Bug
Submit Date:
2010-06-22
Status:
Closed
Updated Date:
2011-03-10
Project Name:
JDK
Resolved Date:
2010-10-26
Component:
client-libs
OS:
windows
Sub-Component:
javax.swing
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u20
Fixed Versions:
6u22-rev (b07)

Related Reports
Backport:
Backport:
Backport:

Sub Tasks

Description
Java (6u20) Applet on Windows (XP SP 2|XP SP 3|Vista|7) in IE (7|8) or FF (3.6.3).
If not mentioned explicitly, configurations not mentioned here don't indicate that there is not a problem with those configs. If you want to check whether the bug exists also in your environment, download the testcase and run it.

The problem is that flickering (and sound) occurs whenever software opens two JOptionPanes in a row. 

    JOptionPane.showMessageDialog(AppletTest.this, "Test 1");
    JOptionPane.showMessageDialog(AppletTest.this, "Test 2");

The first is ok, but if a second follow-up JOptionPane is displayed it always flickers a short time. If the environment supports sound, the user also hears the warning sound of Windows. That behavior (flickering and warning sound) irritates customers actually. 

It is not reproducible when using an Application instead of an Applet. 
(StandaloneTest.java is attached)

It is not reproducible on Solaris.

If the second JOptionPane is shown within SwingUtilities.invokeLater is does not (always) flicker. However, that workaround does not always work. And the customer do not wish to use invokeLater every time a JOptionPane should be shown.

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JOptionPane.showMessageDialog(AppletTest.this, "Test 3");
        }
    }

Runnable Testcase is attached. For IE browsers, open AppletTestForIE.html, for FF browsers, open AppletTestForFF.html.

                                    

Comments
WORK AROUND

Wrap the method by SwingUtilities.invokeLater

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JOptionPane.showMessageDialog(AppletTest.this, "Test 3");
        }
    }

Note that this workaround might not work always.
                                     
2010-06-22
EVALUATION

The flicker is happening because, the 2nd JOptionPane gets rendered while the 1st JOPtionPane blocks the applet with its modal dialog. Hence there is an attempt to raise the blocker to front by invoking ModalityHelper.reactivateDialog(blocker), in the below code snipped from PluginMain.handleMessageSynthesizeWindowActivation():


Dialog blocker = getModalDialogForApplet(appletID);
if (blocker != null) {
    blocker.toFront();
    blocker.requestFocus();
    if (DEBUG) {
        System.out.println("  Called Dialog.toFront() / requestFocus() for blocker of applet ID " + appletID);
    }
    if (lastReactivationTime == 0 ||
        System.currentTimeMillis() > lastReactivationTime +                                                           MIN_REACTIVATION_DELAY) {
        ModalityHelper.reactivateDialog(blocker);
        lastReactivationTime = System.currentTimeMillis();
    }

The System.currentTimeMillis() is > than lastReactivationTime + MIN_REACTIVATION_DELAY for this testcase. Raising the value to 1000 does not help.
                                     
2010-08-24



Hardware and Software, Engineered to Work Together