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

ItemEvent is triggered when items of the choice is selected using keyboard were keyevent is consumed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_10

      Description

      I have a frame, which contains a choice & List. I have added KeyListener, itemListern to the choice. I am consuming the keyevent in keyPressed(). . I try to click on the choice & try to select the item using arrow key. The item event is generated when the items are selected using keyboard. Which is wrong .

      import java.awt.Frame;
      import java.awt.Choice;
      import java.awt.List;
      import java.awt.Robot;
      import java.awt.event.InputEvent;
      import java.awt.event.KeyEvent;

      public class ConsumeEventAndCheckEventFire implements java.awt.event.ItemListener , java.awt.event.KeyListener , java.awt.event.ActionListener {
          private Frame frame=null;
          private Choice ch=null;
          private List lst=null;
          ConsumeEventAndCheckEventFire() {
              frame = new Frame("Test ConsumeEventAndCheckEventFire ");
              frame.setLayout(new java.awt.FlowLayout());
              ch = new Choice();
              ch.add("One");
              ch.add("Two");
              ch.add("Three");
              ch.add("Four");
              ch.add("Five");
              ch.add("Six");
              ch.add("Seven");
              ch.add("Eight");
              ch.add("Nine");
              ch.add("Ten");
              ch.addItemListener(this);
              ch.addKeyListener(this);
              lst = new List();
              lst.add("One");
              lst.add("Two");
              lst.add("Three");
              lst.add("Four");
              lst.add("Five");
              lst.add("Six");
              lst.add("Seven");
              lst.add("Eight");
              lst.add("Nine");
              lst.add("Ten");
              lst.addItemListener(this);
              lst.addKeyListener(this);
              lst.addActionListener(this);
              frame.add(ch);
              frame.add(lst);
              frame.pack();
              frame.setVisible(true);
          }
          public void itemStateChanged(java.awt.event.ItemEvent ie ) {
              System.out.println(ie);
          }
          public void keyPressed(java.awt.event.KeyEvent ke) {
             // System.out.println(ke);
              ke.consume();
          }
          public void keyReleased(java.awt.event.KeyEvent ke){
          }
          public void keyTyped(java.awt.event.KeyEvent ke){
          }

          public void actionPerformed(java.awt.event.ActionEvent ae) {
              System.out.println(ae);
          }
          public static void main(String []args) {
              new ConsumeEventAndCheckEventFire();
          }
      }

      This fails on solaris & pass on windows. I tested this on 1.4.2 to mustang b105 & even in jdk7.0 b10.

        Attachments

          Activity

            People

            Assignee:
            dav Andrei Dmitriev (Inactive)
            Reporter:
            lpremkumsunw Lawrence Premkumar1 (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: