JDK-4436327 : Action events lost from JOption pane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_98
  • CPU: x86
  • Submitted: 2001-04-09
  • Updated: 2002-08-13
  • Resolved: 2002-08-13
Related Reports
Relates :  
Description

Name: ssT124754			Date: 04/09/2001


Java version 1.3.0_01
Java(TM) 2 Runtime Enviroment, Standard Edition (build 1.3.0_01)
Java HotSpot(TM) client vm (build 1.3.0_01,mixed mode)




When ErrorMsg is called via a focusLost event which creates an action event the
dialog box appears. When OK is clicked it loses focus but is still present. The
dialog must be clicked again to regain focus an then the OK button clicked
again to dismiss the dialog box.
This does not happen with other action events.
compile this code enter the first text field then enter the second

package bugreport;

import java.lang.Object;
import java.lang.Number;
import java.lang.NumberFormatException;
import java.lang.Integer;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.HTMLEditorKit;
//import com.borland.jbcl.layout.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import javax.swing.event.*;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
import javax.swing.border.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.sql.Time;
import javax.swing.Timer;
import java.util.StringTokenizer;
import java.math.*;
import netscape.javascript.*;
//import com.borland.jbcl.layout.*;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */

public class Applet1 extends JApplet {
  boolean isStandalone = false;
  JTabbedPane jTabbedPane1 = new JTabbedPane();
  JPanel jPanel1 = new JPanel();
  JTextField TargRelDateTF1 = new JTextField();
  JTextField jTextField2 = new JTextField();
  BorderLayout borderLayout1 = new BorderLayout();
  /**Get a parameter value*/
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }


  public void ErrorMsg(String Msg){
        Object MsgOut=Msg;
        JOptionPane ErrorPane=new JOptionPane();
        ErrorPane.setMessage(MsgOut);
        ErrorPane.createDialog(this,"Error Message");
        ErrorPane.showMessageDialog(null,MsgOut,"Error Message",0);
      }



  /**Construct the applet*/
  public Applet1() {
  }
  /**Initialize the applet*/
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**Component initialization*/
  private void jbInit() throws Exception {
    this.setSize(new Dimension(400,300));
    this.getContentPane().setLayout(borderLayout1);


    TargRelDateTF1.setText("TargRelDateTF1");
    jTextField2.setText("jTextField1");
    this.getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
    jTabbedPane1.add(jPanel1, "jPanel1");
    jPanel1.add(TargRelDateTF1, null);
    jPanel1.add(jTextField2, null);

    TargRelDateTF1.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusLost(FocusEvent e){
      if(TargRelDateTF1.getText().equalsIgnoreCase("Mmm dd yyyy")){
      }else{
      TargRelDateTF1.postActionEvent();
      }
      }
      public void focusGained(FocusEvent g){
      if(TargRelDateTF1.getText().equalsIgnoreCase("Mmm dd yyyy")){
      TargRelDateTF1.selectAll();
      }
      }
});
    TargRelDateTF1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
      Date today=new Date();
      DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT);
      String dateOut = dateFormatter.format(today);
      try{
      SimpleDateFormat sdfInput = new SimpleDateFormat( "MMM dd yyyy" );
      SimpleDateFormat sdfOutput = new SimpleDateFormat ( "MMddyyyy" );
      if(TargRelDateTF1.getText().length()==11){
      String textDate = TargRelDateTF1.getText();
      String textDate1 = TargRelDateTF1.getText();
      int bob=Integer.parseInt(sdfOutput.format(sdfInput.parse(textDate)));
      int bob1=Integer.parseInt(sdfOutput.format(sdfInput.parse(textDate1)));
      int bob3=(bob-bob1);
      }else{
      ErrorMsg("Improper date");
      }
      }catch(ParseException pe){
      String error=pe.toString();
      ErrorMsg(error);
      }
      }
    });

  }
  /**Start the applet*/
  public void start() {
  }
  /**Stop the applet*/
  public void stop() {
  }
  /**Destroy the applet*/
  public void destroy() {
  }
  /**Get Applet information*/
  public String getAppletInfo() {
    return "Applet Information";
  }
  /**Get parameter info*/
  public String[][] getParameterInfo() {
    return null;
  }
  /**Main method*/
  public static void main(String[] args) {
    Applet1 applet = new Applet1();
    applet.isStandalone = true;
    JFrame frame = new JFrame();
    //EXIT_ON_CLOSE == 3
    frame.setDefaultCloseOperation(3);
    frame.setTitle("Applet Frame");
    frame.getContentPane().add(applet, BorderLayout.CENTER);
    applet.init();
    applet.start();
    frame.setSize(400,320);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height -
frame.getSize().height) / 2);
    frame.setVisible(true);
  }

  //static initializer for setting look & feel
  static {
    try {
      //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName
());
    }
    catch(Exception e) {
    }
  }
  void TargRelDateTF1_actionPerformed(ActionEvent e) {

  }
  void TargRelDateTF1_focusGained(FocusEvent e) {

  }
  void TargRelDateTF1_focusLost(FocusEvent e) {

  }
}
(Review ID: 119564) 
======================================================================

Comments
EVALUATION Here was the series of events in 1.3.0_01: 1. JTextField gets focusLost and therefore displays the dialog. 2. The dialog takes focus and for some reason another focusLost is sent to the JTextField. 3. JTextField shows another dialog. The reason OK had to be clicked twice is because there were two dialogs on top of one another. As of 1.4.0, this problem is no longer reproducible. I assume it was fixed in the focus re-write. However, since this isn't my area of expertise, and the appearance of being fixed might just be timing related, I'll re-assign to AWT to determine this bug's status. ###@###.### 2002-05-06 Name: osR10079 Date: 08/13/2002 In 1.3, when user shows dialog on FOCUS_LOST, text field receives FOCUS_LOST twice, and we have two modal dialogs. This was fixed during focus rearchitecture project. But new problem was introduced by this rearchitecture (showing modal dialog in focus events handlers, bug id 4531693). And this problem is fixed in first build of 1.4.2. So, we can close this bug (or mark it as fixed). ###@###.### Aug 13, 2002 ======================================================================
24-08-2004

WORK AROUND Name: ssT124754 Date: 04/09/2001 none ======================================================================
24-08-2004