-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.4.2
-
x86
-
windows_2000
FULL PRODUCT VERSION :
jdk 1.4.0, jdk 1.4.1, jdk 1.4.2
FULL OS VERSION :
Windows 2000
A DESCRIPTION OF THE PROBLEM :
A form uses 3 JTextFields: t1, t2, t3.
After pressing enter in t1 I want transfer focus to t3 and disable t1 (and sometimes t2 too).
The result of the simple test application inluded is:
After pressing return in t1, t2 receives focus.
When I disable t2 too, focus get completely lost.
bug is new in all 1.4.x, 1.3.x produced the right results.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
control with call of requestFocsus (t3) should receive focus.
ACTUAL -
focus in wrong control or completely lost
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame
{
private JTextField t1 = new JTextField(5),
t2 = new JTextField(5),
t3 = new JTextField(5);
public static void main(String args[]) { new Test().setVisible(true); }
public Test()
{
Container c = getContentPane();
c.setLayout(new GridLayout(1,3,5,5));
c.add(t1);
c.add(t2);
c.add(t3);
pack();
t1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
t3.requestFocus();
t1.setEnabled(false);
// uncomment the following line and focus
// will be nowhere
// t2.setEnabled(false);
}});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
switch order of setEnabled / requestFocus calls.
It seems that the new logic of automatic focus transfer when disabling the current focus owner causes the problem. It' doesn't recognize that there was a requestFocus call to a different control before.
It looks like the requestFocus call doesn't immediately transfer focus (like Win32-API SetFocus) but uses some kind of asynchronous notificaton. Otherwise Swing wouldn't still recognize t1 as focus owner.
(Review ID: 189643)
======================================================================
- relates to
-
JDK-4687245 On TAB, JSpinner first turns focus, then calls ChangeListener
- Open
-
JDK-6180261 Focus error when disabling in focus JTextField from TreeSelectionListener
- Closed
-
JDK-4781423 Alt Key Errors and NullPointerException After Removal of Container with Focus
- Closed
-
JDK-4867005 When removing a JPanel, child JButton gets a FOCUS_GAINED
- Closed
-
JDK-6411406 Components automatically transfer focus on removal, even if developer requests focus elsewhere first
- Closed
-
JDK-4685768 A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
- Closed