JDK-4838730 : REGRESSION: In JTextArea setEditable(...) breaks focus traversal keys
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-03-27
  • Updated: 2017-05-16
  • Resolved: 2003-11-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b28Fixed
Related Reports
Relates :  
Description

Name: rmT116609			Date: 03/27/2003


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

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
If you have a JTextArea where you have explicitly set the focus traversal keys to be used using the setFocusTraversalKeys(...) method and you make a subsequent call to setEditable(false) and then setEditable(true), the focus traversal keys that have been set no longer function.

This is a big issue for screens where fields start off non-editable until you enter an id or something at which time the fields are set editable (which we do all over our application).

I tested this in using JDK1.4.1_02, JDK1.4.1_01, and JDK1.4.0.  It appears to be broken in both of the 1.4.1 release but works fine in the 1.4.0 release.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1). Run the example code provided.
2). Using the <tab> key you should be able to traverse from the JTextField to the JTextArea to the next JTextField and so on.
3). Press the 'Break Focus' button.
4). Now if you put focus into the top JTextField and press <tab> to navigate into the JTextArea, subsequent <tab> presses will add tabs to the JTextArea instead of transfering focus to the next JTextField

EXPECTED VERSUS ACTUAL BEHAVIOR :
Regardles of when setEditable(boolean) is called on a JTextArea, any focus traversal keys that have been explicitly set should always function.
Calling setEditable(boolean) on the JTextArea seems to cancel out any previously set focus traversal keys making the JTextArea not function how it was designated to function.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class Example extends JFrame implements ActionListener
{
    public static void main(String [] args)
    {
        Example e = new Example();
        e.pack();
        e.setVisible(true);
    }

    public Example()
    {
        super("Example");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        ta = new JTextArea(5,20);
        HashSet keys = new HashSet(1);
        keys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0, false));
        ta.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys);
        keys = new HashSet(1);
        keys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK, false));
        ta.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys);

        JPanel p = new JPanel(new BorderLayout());
        p.add(new JTextField(), "North");
        p.add(new JScrollPane(ta), "Center");
        p.add(new JTextField(), "South");
        getContentPane().add(p, "Center");

        p = new JPanel();
        JButton b = new JButton("Break Focus");
        b.addActionListener(this);
        p.add(b);
        getContentPane().add(p, "South");
    }

    public void actionPerformed(ActionEvent e)
    {
        ta.setEditable(false);
        ta.setEditable(true);
    }
	
    private JTextArea ta;
}
---------- END SOURCE ----------

Release Regression From : 1.4.0_03
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: 183103) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b28 tiger-beta
14-06-2004

EVALUATION Name: ik75403 Date: 03/28/2003 BasicEditorPaneUI and BasicTextAreaUI calls updateFocusTraversalKeys on changing editorKit and on changing editable state. BasicTextUI.updateFocusTraversalKeys removes VK_TAB from forwardTraversalKeys and removes VK_TAB SHIFT_MASK from backwardTraversalKeys for editable component. see 4514331 for more details. ======================================================================
11-06-2004