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

TextComponent.getCaretPosition() treats VK_ENTER characters as if they were 2 ch

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • client-libs
    • None
    • x86
    • windows_nt



      Name: sg39081 Date: 07/01/97


      - derive a class from java.awt.TextArea implementing KeyListener.
      - override processKeyEvent.
      - in processKeyEvent if the user types in a VK_TAB then consume
      the event and call TextArea.insert(" ", getCaretPosition());
      - run the code and type in bunch of text including a couple
      of VK_ENTER's.
      - Go the the second line, first column and type a VK_TAB.
      - the 4 spaces will get inserted incorrectly.

      NOTE: same problem using getStartPosition() and getEndPosition()

      EXAMPLE:
          protected void processKeyEvent(KeyEvent e)
          {
              if (e.getKeyCode() == KeyEvent.VK_UNDEFINED // KEY_PRESSED
              && e.getKeyChar() == KeyEvent.VK_TAB)
              {
                  // insert 4 spaces at the current caret position
                  insert(" ", getCaretPosition());
                  e.consume();
              }
          }




      ======================================================================

            ehawkessunw Eric Hawkes (Inactive)
            sgoodsunw Sheri Good (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: