Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4737679

Alt+Left/right/up/down generate characters in JTextArea

XMLWordPrintable

    • 04
    • x86
    • windows_nt, windows_2000



        Name: pa48320 Date: 08/27/2002


        Put the focus in a JTextArea and press Alt+Right, this types a "B".
        I tried to trace the origin of the problem and it seems to come from the type-ahead feature that generates a keyTyped event.
        This is a major problem for JDeveloper since those keys are used to navigate between editors.

        The following case is a trivial application that creates a JTextArea. Run the application and type Alt+Left, Alt+Right, Alt+PgUp, ... and you will see that characters are typed into the text.

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

        public class Application1
        {
          public static void main(String[] args)
          {
            JFrame frame = new JFrame();
            frame.getContentPane().setLayout(new BorderLayout());
            frame.getContentPane().add(new JTextArea());
            frame.setBounds(100, 100, 200, 200);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
          }
        }

        The problem is reproducable with JDK1.4.0 and 1.4.1 but was not present in previous releases.
        (Review ID: 163671)
        ======================================================================
        I can reproduce the bug on Win2k.
        Do not see what it has to do with the text package.
        Take a look at the following example.

        --

        import java.awt.*;
        import java.awt.event.*;

        public class Application1 {
            public static void main(String[] args) {
        Frame frame = new Frame();
        Panel panel = new Panel();
        frame.add(panel);
        panel.addKeyListener(
        new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
        System.out.println("Application1.keyPressed "+e);
        }

        public void keyTyped(KeyEvent e) {
        System.out.println("Application1.keyTyped "+e);
        }
        public void keyReleased(KeyEvent e) {
        System.out.println("Application1.keyReleased " + e + "\n");
        }
        }
                );
        frame.setBounds(100, 100, 200, 200);
        frame.setVisible(true);
            }
        }

        --

        When Alt+Right is pressed
        java.awt.event.KeyEvent[KEY_TYPED, keyCode=0, keyChar='B', keyLocation=KEY_LOCATION_UNKNOWN] get generated.

        That is why 'B' is typed in JTextArea.

        ###@###.### 2002-09-04

              kdmsunw Kdm Kdm (Inactive)
              pallenba Peter Allenbach (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: