JDK-4742005 : 1.4.1 REGRESSION: JTextField.requestFocus() isn't transfering focus with Linux
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2002-09-05
  • Updated: 2002-11-12
  • Resolved: 2002-11-12
Related Reports
Duplicate :  
Description

Name: jk109818			Date: 09/04/2002


FULL PRODUCT VERSION :
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)


FULL OPERATING SYSTEM VERSION :
Debian GNU/Linux, Kernel 2.4.18, libc 2.2.5


A DESCRIPTION OF THE PROBLEM :
A JTextField calling requestFocus() after a JDialog is
closed does not work on Linux with 1.4.1 (beta or RC)

Works fine on Windows.

REGRESSION.  Last worked in version 1.4

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Add a JTextField to a frame
2. Launch a JDialog (or JOptionPane)
3. After the dialog closes call JTextField.requestFocus()

EXPECTED VERSUS ACTUAL BEHAVIOR :
With 1.3.1, and 1.4 on Linux and 1.4.1 on Windows the
JTextField is given focus when the dialog closes.

With 1.4.1 on Linux the JTextField does not have focus, ie I
can't type in the TextField without first clicking in it.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class TestFrame extends JFrame {
    private JPanel m_pnlMain = new JPanel();
    private JTextField m_txtInput = new JTextField();
    private JButton m_btnClickMe = new JButton("Click Me");
    private GridBagLayout m_gbLayout = new GridBagLayout();

    public TestFrame() {
        m_pnlMain.setLayout(m_gbLayout);
        m_btnClickMe.addActionListener(new ButtonAdapter(this));
        getContentPane().add(m_pnlMain, BorderLayout.CENTER);

        m_pnlMain.add(m_btnClickMe,        new GridBagConstraints(0, 1, 1, 1,
0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(6,
12, 13, 13), 0, 0));
        m_pnlMain.add(m_txtInput,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(13,
12, 6, 13), 50, 0));
    }

    public static void main(String[] args) {
        TestFrame testFrame = new TestFrame();
        testFrame.pack();

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = testFrame.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        testFrame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);

        testFrame.setVisible(true);

    }

    protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
        }
    }

    void buttonClicked() {
        JOptionPane.showMessageDialog(this, "Test");
        m_txtInput.requestFocus();
    }
}

class ButtonAdapter implements ActionListener {
    private TestFrame adaptee;

    ButtonAdapter(TestFrame adaptee) {
        this.adaptee = adaptee;
    }
    public void actionPerformed(ActionEvent e) {
        adaptee.buttonClicked();
    }
}
---------- END SOURCE ----------

Release Regression From : 1.4
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 163804) 
======================================================================

Comments
EVALUATION The sequence of events when the dialog closes is to request focus on the text field, a WINDOW_GAINED_FOCUS event is some how generated for the JDialog (used by the JOptionPane) which results in focus owner thinking the JDialog should have focus, the dialog loses focus and the focus owner then becomes null, and then the JFrame ends up with focus. I am reassigning to awt as it seems the WINDOW_GAINED_FOCUS event is being processed too late. ###@###.### 2002-09-05 Name: dmR10075 Date: 09/09/2002 It seems to be the same race as in 4697451 - one thread processes WINDOW_GAINED_FOCUS, another requests focus. Moreover, bug dissappeared in the workspace with the fix for 4697451. ###@###.### 2002-09-09 ====================================================================== The fix for 4697451 was integrated into 1.4.2b04 and starting from that build this bug is no more reproducible. These bugs have the same cause, and now it is fixed. Closing as duplicate. ###@###.### 2002-11-12
12-11-2002