Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2008, 10:11 PM
Member
 
Join Date: Feb 2008
Posts: 1
JavaNerd is on a distinguished road
Can't edit JTextField after modal dialog
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 1.5.0.12 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");
cmd.addActionListener(this);
c.add(textField, BorderLayout.CENTER);
c.add(cmd, BorderLayout.EAST);
}

public void actionPerformed(ActionEvent e)
{
JOptionPane.showConfirmDialog(this, "Hello World!");
// <<<<< PROCESSING INSERTED HERE
// <<<<< If processing is done after the confirmation,
// <<<<< the problem occurs more often.
textField.setText(“Count: “ + intValue);
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:

<Html>
<Head>
<Title>Test Applet</Title>
</Head>

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

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,
Ken
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a modal JFrame? surot New To Java 10 04-11-2008 07:40 AM
I need help with my java servlet homework(add,edit and delete) jellyfish888 Java Servlet 3 12-26-2007 07:42 AM
how to edit lines. jason27131 New To Java 1 08-01-2007 05:41 AM
How To Edit/Add JSP Pages in NetBeans IDE JavaForums NetBeans 0 07-31-2007 12:13 AM
Doubt in edit and delete methods ai_2007 Advanced Java 3 07-01-2007 12:40 PM


All times are GMT +3. The time now is 01:18 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org