JDK-4186905 : JTextPane no longer dispatches keyTyped events to a KeyListener
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.6,1.2.0,1.2.1
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,solaris_2.5.1,windows_95,windows_98,windows_nt generic,solaris_2.5.1,windows_95,windows_98,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1998-11-03
  • Updated: 1999-04-28
  • Resolved: 1999-04-28
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 Other
1.2.2 1.2.2Fixed 1.3.0Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
********************************************************************************

This bug record is specific to Java 2 SDK Standard Edition v. 1.2 and v. 1.2.1.

Please do not add customer calls relating to 1.1.x to this record.

********************************************************************************

Name: tb29552			Date: 11/03/98


/*
JTextPane no longer dispatches keyTyped events

The following code reproduces this problem.
When run under i586/win_nt_4.0 you will see
only the keyPressed and keyReleased events.

Run the same demo under SPARC/Solaris and you
will see keyPressed, keyTyped and keyReleased
for each key you strike.

This showed up under JDK 1.2 RC 1 and worked
fine under JDK 1.2beta4:
*/

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

/**
 * Demonstrates problems with JDK1.2 RC 1--JTextPane no longer
 * dispatches keyTyped events like it used to in JDK1.2beta4.  Typing
 * some characters in the pane after startup will show that only
 * keyPressed and keyReleased events are generated...
 */
public class TestJTP  {
    private static final float INITIAL_DOC_HEIGHT_PERCENT = 0.20f;
    private static final float INITIAL_WIDTH_PERCENT = 0.37f;
    public static void main(String[] argv) {
        JFrame aFrame = new JFrame();
        Dimension aScreenRes = Toolkit.getDefaultToolkit().getScreenSize();
        aScreenRes.height = (int) (INITIAL_DOC_HEIGHT_PERCENT
                                   * aScreenRes.height);
        aScreenRes.width = (int) (INITIAL_WIDTH_PERCENT
                                  * aScreenRes.width);
        JTextPane itsTextPane = new JTextPane();
        JScrollPane itsScrollPane = new JScrollPane(itsTextPane,
                                   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        itsScrollPane.setPreferredSize(aScreenRes);
        // Register the listener to keep track of keyboard events:
        itsTextPane.addKeyListener(
                                   new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                System.out.println("Key type detected:" + e.getKeyChar());
            }
            public void keyPressed(KeyEvent e) {
                System.out.println("Key press detected:" + e.getKeyChar());
            }
            public void keyReleased(KeyEvent e) {
                System.out.println("Key release detected:" + e.getKeyChar());
            }
        }
        );
        aFrame.getContentPane().setLayout(new BorderLayout());
        aFrame.getContentPane().add(itsScrollPane, "Center");
        aFrame.pack();
        aFrame.setVisible(true);
    }
}

(Review ID: 41481)
======================================================================


daniel.indrigo@Canada 1999-01-19

JTextfield has the same problem 

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.2.2 FIXED IN: 1.2.2 INTEGRATED IN: 1.2.2 kestrel
14-06-2004

WORK AROUND Add an InputMethodListener to the component. The sequence of characters entered is the combination of characters in KEY_TYPED key events and committed characters in input method events. norbert.lindenberg@Eng 1999-04-28
28-04-1999

EVALUATION On windows, instead of a KeyTyped event being dispatched an InputMethodEvent of type INPUT_METHOD_TEXT_CHANGED is being passed in. JTextComponent, in the constructor, does a enableEvents(AWTEvent.INPUT_METHOD_EVENT_MASK) which is why the input methods are enabled. The JTextCompoments will add the text via the processInputMethodEvent method, which is why new text is displayed even though the keyTyped isn't passed on. I am reassigning this to classes_awt_im and bumping the priority. scott.violet 1999-03-22 naoto@eng implemented a compatibility mode in JTextComponent for applications that do not handle input method events. In this compatibility mode, key events are generated from committed text and sent to the component via processKeyEvent. The implementation has been put back, but I'm still planning to add documentation to describe JTextComponent's interaction with input methods. This documentation has to be different for Swing in Java 2 and Swing for 1.1. norbert.lindenberg@Eng 1999-04-07 The documentation was updated for the Cricket Q build. norbert.lindenberg@Eng 1999-04-28
07-04-1999