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

Can't remove VK_TAB from JTextArea

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs



      Name: stC104175 Date: 05/02/2000


      > java -version
      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)
      kiadm@DATA /dwk_lg/prog
      >

      I want to use an JTextArea in the following way. If the user press the TAB-key
      the focus should change to the next component or by SHIFT+TAB the previous
      component. So I implemented an KeyListener and it's work still fine, but a
      tabulator was insert into the JTextArea. So I'm remove the KeyStroke from the
      Keymap of JTextArea. With JDK1.2.2 this works, but in Kestrel the TAB was insert
      into the JTextArea.
      Try is with following Example. The Test-Textarea show the bug, if you press four
      times TAB and then SHIFT+TAB.

      Here is the sample code:

      I want to use an JTextArea in the following way. If the user press the TAB-key
      the focus should change to the next component or by SHIFT+TAB the previous
      component. So I implemented an KeyListener and it's work still fine, but a
      tabulator was insert into the JTextArea. So I'm remove the KeyStroke from the
      Keymap of JTextArea. With JDK1.2.2 this works, but in Kestrel the TAB was insert
      into the JTextArea.
      Try is with following Example. The Test-Textarea show the bug, if you press four
      times TAB and then SHIFT+TAB.// @(#)KeymapProblem.java
      // This little program demononstrate a bug that I found in java 1.2 and Kestrel.
      // The problem is that the method removeKeyStrokeBinding from the class Keymap
      // doesn't work as described.
      // In JAVA 1.2 I wan't to remove every KeyStroke like ALT+'A' from any
      JTextField,
      // but the JTextField doesn't ignore the keystroke.
      // In Kestrel the JTextfields ignore automatically any keystroke like ALT+'A',
      but the
      // JTextArea doesn't ignore the TAB-Key after I remove this KeyStroke. This
      works in 1.2
      // really fine.
      //
      // (C) 2000 PPI FiNANCIAL SYSTEMS
      //
      // MANIFEST KEYMAPMANIFEST.TXT
      /*
      Main-Class: KeymapProblem
      Implementation-Vendor: "PPI Financial Systems"
      */
      //
      // jar -cfm Keymap.jar KeymapManifest.txt KeymapProblem*
      //


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

      public class KeymapProblem
          extends JFrame
          implements ActionListener, KeyListener {

          //Constants
          private final static String TEST_TF = "Test-TextField: ";
          private final static String DUMMY_BT = "Dummy-Button";
          private final static String DUMMY_TF = "Dummy-Textfield";
      private final static String TEST_TA= "Test-TextArea";

          //Some static variables and methods for trace.
          private static int indent = 0;

          private static void traceEnter(String method) {

              for (int i = 0; i < indent; i++) {
                  System.out.print(" | ");
              }
              System.out.println("> "+method);
              indent++;
          }

          private static void traceLeave(String method) {
              indent--;

              for (int i = 0; i < indent; i++) {
                  System.out.print(" | ");
              }
              System.out.println("< "+method);
          }

          private static void tracePut(String txt) {
              for (int i = 0; i < indent; i++) {
                  System.out.print(" | ");
              }
              System.out.println(txt);
          }


          //Variables
          /** Test-Textfield */
          private JTextField testTF;

          /** DUMMYTextfield */
          private JTextField dummyTF;

          /** DUMMY-Button */
          private JButton dummyBT;

      /** Test-TextArea */
      private JTextArea testTA;

          //Constructor

          public KeymapProblem() {
              super("Keymap - JRE-Version "+ System.getProperty("java.version"));


              // Instanziieren der Komponenten
              testTF = new JTextField(5);
              testTF.setActionCommand(TEST_TF);

              dummyBT = new JButton(DUMMY_BT);
              dummyBT.setActionCommand(DUMMY_BT);
              dummyBT.setMnemonic('D');

              dummyTF = new JTextField(5);
              dummyTF.setActionCommand(DUMMY_TF);

      testTA = new JTextArea();

          getContentPane().setLayout(new GridLayout(3,2,10,15));

              getContentPane().add(new JLabel(TEST_TF));
              getContentPane().add(testTF);
              getContentPane().add(dummyBT);
              getContentPane().add(dummyTF);
              getContentPane().add(new JLabel(TEST_TA));
      getContentPane().add(testTA);

              //Set focus-order
              testTF.setNextFocusableComponent(dummyBT);
              dummyBT.setNextFocusableComponent(dummyTF);
              dummyTF.setNextFocusableComponent(testTA);
              testTA.setNextFocusableComponent(testTF);

              dummyBT.addActionListener(this);
              testTA.addKeyListener(this);

      changeKeymap();

              this.pack();
              this.setLocation(100,100);
              this.setVisible(true);
          }

          //main-method
          public static void main(String[] args) {
              new KeymapProblem();
          }


      private void changeKeymap()
      {
      traceEnter ("changeKeymap");

      Keymap areaMap = testTA.getKeymap();
      Keymap fieldMap = testTF.getKeymap();
      KeyStroke keyStroke = null;

      keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
      areaMap.removeKeyStrokeBinding(keyStroke);

      for (int vk = KeyEvent.VK_A; vk <= KeyEvent.VK_Z; vk++) {
      // Die virtuellen Keys 65 -91 sind A-Z
      fieldMap.removeKeyStrokeBinding(KeyStroke.getKeyStroke(vk, Event.ALT_MASK));
      areaMap.removeKeyStrokeBinding(KeyStroke.getKeyStroke(vk, Event.ALT_MASK));
      }

      traceLeave ("changeKeymap");
      }





          //ActionListener-Methods
          public void actionPerformed(ActionEvent aE) {
              String strVal = "";
              double doubleVal = 0;

              traceEnter("actionPerformed");
              //tracePut(aE.getSource().toString());
              tracePut(aE.getActionCommand());
              if (aE.getActionCommand().equals(DUMMY_BT)) {
      JOptionPane.showMessageDialog(this, "Thanks you have make and old button very
      happy!",
      "Message", JOptionPane.INFORMATION_MESSAGE);
              }
              traceLeave("actionPerformed");
          }

      public final void keyPressed(KeyEvent kE) {
      traceEnter("keyPressed");
      switch (kE.getKeyCode()) {
      case KeyEvent.VK_TAB :
      switch (kE.getModifiers()) {
      case 0 :
      javax.swing.FocusManager.getCurrentManager().
      focusNextComponent((JComponent) kE.getSource());
      break;
      case Event.SHIFT_MASK :
      javax.swing.FocusManager.getCurrentManager().
      focusPreviousComponent((JComponent) kE.getSource());
      break;
      }

      }
      traceLeave("keyPressed");
      }

      public final void keyTyped(KeyEvent kE) { };

      public final void keyReleased(KeyEvent kE) { };


      }
      (Review ID: 103930)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            stompkinsunw Sean Tompkins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: