JDK-4398269 : Problems with OptionPane in FocusLost
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-12-14
  • Updated: 2002-01-15
  • Resolved: 2002-01-15
Related Reports
Duplicate :  
Description

Name: boT120536			Date: 12/14/2000


JDK 1.3 final release for Windows

Try the following test class.
1) Set the focus into the TextField und press the button (hold down the mouse
button for a second) or use the Mnemonic. The ActionEvent apears before the
OptionPane opens. I think this is wrong. Move the mouse above the Button
and it will be painted pressed if the mouse is above the button (wrong, too).
2) Start the test and set the focus into the TextField, again. Move the mouse
above the Button and press the mouse button very short (just a short klick).
No ActionEvent apears (not before and not after the OptionDialog).

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

public class Dialog implements FocusListener, ActionListener {
    public static void main(String[] args) {
        JFrame frame = new JFrame("OptionPane in FocusLost");
        JTextField textField = new JTextField("Halilalo");
        textField.addFocusListener(new Dialog());
        JButton button = new JButton("Button");
		button.addActionListener(new Dialog());
		button.setMnemonic('B');
        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(textField);
        frame.getContentPane().add(button);
        frame.pack();
        frame.setVisible(true);
    }

	public void actionPerformed(ActionEvent e) {
		System.out.println("actionPerformed");
	}

    public void focusLost(FocusEvent e) {
//        System.out.println(e);
System.out.println("focusLost "+e.isTemporary());
        if (!e.isTemporary()) {
System.out.println("showMessageDialog");
            JOptionPane.showMessageDialog(null, "Hallo");
        }
    }

    public void focusGained(FocusEvent e) {
//        System.out.println(e);
    }
}
(Review ID: 107250) 
======================================================================

Comments
EVALUATION JButton notifies ActionListeners on a release. This test keys off a focus lost event to bring up the dialog. When you click on the button the focus lost event is generated and the dialog comes up. The dialog causes the mouse release event not to be generated, thus the button stays pushed and the action listener is not notified. I'm going to reassign this to AWT to see if there is anyway to guarantee a Component can get a release. If it isn't possible with the current architecture, perhaps new API could be added for components they need to see a mouse release. scott.violet@eng 2001-03-27 I think this is a duplicate of 4368790, which I just reassigned to Brent. I am reassigning this one as well, so that he can make sure that's true. hania.gajewska@Eng 2001-04-17 Yes, this is a dup of 4368790, and the same fix should work. ###@###.### 2002-01-14
17-04-2001