Skip to main content

Modal dialog behaviour with new plugin

2 replies [Last post]
macintyrei
Offline
Joined: 2008-03-26

I have noticed some weird behaviour with modal dialogs when using an applet running under the new plugin.

1. Performance. Modal Dialogs are much slower to dispose than under the old plugin. After clicking the close button on a modal dialog the dialog takes about 1-2 seconds to disappear (you see the dialog lose focus before disappearing). In addition, clicking outside the dialog results in a very slow dialog focus flicker. In the old plugin there was a very quick focus flicker (mimicking how Windows does it I presume). In the new dialog I see the dialog lose focus, after a second the parent browser get the focus, then focus is passed back to the dialog. This behaviour repeats a few times until the dialog regains permanent focus (it takes about 3.5 seconds).

2. Controls on a modal dialog stop working. I have seen this intermittently with JComboBoxes. The scenario is as follows:

A Modal dialog has a combo on it and is displayed. Clicking on the combo works as expected and drops down the combo list. Now click outside the modal dialog onto the main browser window. The dialog will lost/gain focus a couple of times (slowly - see point 1 above). When the focus finally returns to the dialog clicking on the combo will *sometimes* fail to drop down the combo list. It does not happen all the time so I am guessing there is some kind of timing issue.

I see the issue with both windows L&F as well as the default L&F. If I revert to the old plugin everything works as expected. Nothing untoward appears in the java console.
Running as a stand alone application is also fine.

System config as follows
WinXP Pro SP2
IE6
java version "1.6.0_10-beta"
Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b14)
Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing)

[pre]
// sample applet
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class TestModal extends JApplet {

public void init() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
setLayout(new FlowLayout());
JButton button = new JButton("click for dialog");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new ModalDialog(SwingUtilities.getWindowAncestor(TestModal.this));
}
});
getContentPane().add(button);
}
});
super.init();
}

static class ModalDialog extends JDialog {
public ModalDialog(Window owner) {
super(owner);
setModal(true);
setSize(400, 300);
setLayout(new FlowLayout());

final JComboBox combo = new JComboBox(
new Object[] { "1", "2", "3" });
combo.setPreferredSize(new Dimension(80, 30));
getContentPane().add(combo);

JButton button = new JButton("close");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
getContentPane().add(button);

setLocationRelativeTo(owner);
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
setVisible(true);
}
}

/**
* Entry point for testing stand alone app
*/
public static void main(String [] argv) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
final JFrame jf = new JFrame();
jf.setLayout(new FlowLayout());
JButton button = new JButton("click for dialog");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new ModalDialog(jf);
}
});
jf.getContentPane().add(button);
jf.setSize(800, 600);
jf.setLocationRelativeTo(null);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
});

}

}
[/pre]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
yevgenij
Offline
Joined: 2008-12-16

I encountered a similar problem in code and the line:

comboBox.setRequestFocusEnabled(true);

fixed the problem of disappearing combobox.
However, it is of course not always accaptable solution.

kbr
Offline
Joined: 2003-06-16

Thanks for the report and the test case. The nested message pump that we use both during JavaScript-to-Java calls and while modal dialogs are active is one of the tricky areas in the new plug-in that has undergone some iteration. The old plug-in's code for this is pretty complicated and browser-specific, and during the rewrite we attempted to fuse and simplify it, but it probably requires more work.

I can't reproduce the slow disposal of the modal dialog with the current code, but can definitely see that in some circumstances running your test case in IE the combo box doesn't appear, and that this appears to be related to message handling in the Java Plug-In rather than anywhere else in the graphics stack. We'll look into this further.

I've filed 6681818 about this; it will show up in the Sun Bug Database tomorrow or the day after.