Hi everyone. I've been lurking here for a while, but this is the first topic I have started. This is an Applet/Java Swing question, so I wasn't sure where to post, but this subforum seemed appropriate. I have also submitted this information at the Sun bugs website, but I was wondering if anyone here has had a similar problem, and may know of a workaround.

Here goes:
I am having a problem where text fields cannot be edited following the use of JOptionPane to open a Modal dialog in a JApplet. When I try to click in the JTextField area after closing the confirmation window, the browser doesn’t allow it. Clicking somewhere outside the applet window in the browser (the white area) fixes the problem and then I can click the text field and edit it.

This problem happens when using Mozilla SeaMonkey 1.0.1 in the Linux AS3 environment and Firefox in the Linux ES5 environment. The version of the plugin is “application/x-java-applet;jpi-version=1.5.0_04”. I have tried other versions of the plugin (including version 1.6.0_04), but they don’t fix the problem either.

This bug seems to be similar or related to one that was opened a while ago:
Bug ID: 6432035 Unable to edit content of JTextField intermittently following modal dialog

Here is the code that has the problem:

package test;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TestApplet extends JApplet implements ActionListener
private JTextField textField;
private JButton cmd;
private int intValue;

public void init() {
intValue = 1;
Container c = getContentPane();
textField = new JTextField("Hello");
cmd = new JButton("Click Me");
c.add(textField, BorderLayout.CENTER);
c.add(cmd, BorderLayout.EAST);

public void actionPerformed(ActionEvent e)
JOptionPane.showConfirmDialog(this, "Hello World!");
// <<<<< If processing is done after the confirmation,
// <<<<< the problem occurs more often.
textField.setText(“Count: “ + intValue);

Another important note is that if I put some processing following the confirmation, the problem happens much more frequently. For example, I have put a loop with some statistical calculations that take a few milliseconds to perform, and when this is done the problem happens almost every time. Even inserting the following sleep causes the problem to occur almost every time:

try {Thread.sleep(10);} catch (InterruptedException e) {}

I even tried putting the entire processing of the actionPerformed method into it’s own thread, and the problem still occurs. I have tried numerous other things such as forcing repaints, etc. and nothing I have tried programmatically helps.

Another thing I noticed is that when the problem occurs, focus is lost from the Applet. When it works okay, the focus remains on the JButton that was last clicked (that invoked the action that opened the dialog).

As a side note, I have run this same Applet in Firefox and Internet Explorer in the Windows environment, and it works fine there. I rewrote the “simple” example code (above) as an application and that works fine.

If there are any workarounds, or if there is a fix for this problem, please let me know about anything that can be done programmatically to resolve this problem.

Here is the HTML for the Applet:

<Title>Test Applet</Title>

Main Page<br>
Applet Below<br>
<Applet Code="TestApplet.class" width=200 height=100>

How to reproduce:

1. Open the Applet in your Browser.
2. Click the "Click Me" button.
3. Wait a second, and then try to click and edit the Text field.

When the problem occurs I cannot gain focus on the text field (or edit it), focus is always lost (from button that was just clicked).

Any help would be greatly appreciated.

Thanks very much,