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

Cannot trap and handle keyboard events in TextArea component

    XMLWordPrintable

Details

    • 1.0.2
    • sparc
    • solaris_2.4, solaris_2.5
    • Verified

    Description

      As of the JDK FCS 1.0 release it is now supposed to be possible to intercept at
      least keyboard events in components, by subclassing the components and overriding
      the handleEvent method.

      This works fine for TextField, but fails dismally for TextArea, which seems incapable
      of allowing you to intercept any events.

      Try this test case

      import java.awt.*;
      import java.applet.*;
      import java.lang.*;
      import java.io.*;

      public final class eventTest extends Applet {
                     InputTextField inputField; // single-linetype-in area;
                     InputTextArea inputArea; // multi-line type-in area
         
           public eventTest() {
          }

                     
          public static void main(String args[]) {

              Frame f = new Frame("Event Test");
              
             eventTest eT = new eventTest();
             eT.init();
             eT.start();
             f.add("Center", eT);
             f.resize(300,200);
             f.show();
          }


           public void init() {

             Panel p = new Panel();
             p.setLayout(new BorderLayout());
             add(p);

             inputArea = new InputTextArea("", 4,20);
             p.add("Center",inputArea);

             inputField = new InputTextField("", 20);
             p.add("South",inputField);

          }

      }

      class InputTextField extends TextField {

         public InputTextField(String s, int cols) {
              super(s,cols);

         }

        public boolean handleEvent(Event e) {

         System.out.println("caught TextField event");
        return super.handleEvent(e);
             
        }
      }

      class InputTextArea extends TextArea {

         public InputTextArea(String s, int rows, int cols) {
              super(s,rows,cols);

         }

        public boolean handleEvent(Event e) {

         System.out.println("caught TextArea event");
         return super.handleEvent(e);
        }
      }

      The description field as copied from bug report 1239033 follows:

      TextArea components do not appear to generate KeyDown/KeyUp events that applications
      can observe. This makes creating applications like chat programs difficult.

      Attachments

        Issue Links

          Activity

            People

              amfowler Anne Fowler (Inactive)
              prr Philip Race
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: