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

REGRESSION: Choice subclass does not popup >= JVM 1.4

XMLWordPrintable

    • x86
    • windows_98

      FULL PRODUCT VERSION :
      1.4.2_02

      ADDITIONAL OS VERSION INFORMATION :
      Windows 98 [Version 4.10.1998]
      Windows XP

      A DESCRIPTION OF THE PROBLEM :
      I created a subclass of Choice since I wanted to use Tab key for nagivation within another control. This worked fine in Personal Java, JVM 1.2.2, 1.3.1. however, in 1.4.1, 1.4.2, the popup menu no longer appears.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      in sample app provided, select top two menus.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      both menus should popup

      ACTUAL -
      1st menu (Choice) pops up as expected.
      2nd menu (ChoiceNT) pops up < JVM 1.4; doesn't popup for 1.4.2

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;

      /*
      example that illustrates 2 problems with JVM >= 1.4 (at least on Windows)

      1. popup doesn't work for subclass of Choice
      2. keyevents lost

      these works fine in Personal Java, JVM 1.2.2, 1.3.1

      S. Weyer ###@###.###
      */

      public class ChoiceKeyTest
        extends Frame
        implements ActionListener
      {

        Choice choice1;
        ChoiceNT choice2;
        Button keyButton;
        KeyText text1, text2;
        char keyLetter;
        StringBuffer sb = null;

        public static void main(String[] args) {
          new ChoiceKeyTest();
        }

        public ChoiceKeyTest() {
          setTitle("ChoiceKeyTest; Java: " + System.getProperty("java.version"));
          addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent ev) {
                try { System.exit(0); }
                catch (IllegalStateException ignore) {}; // from Mac possibly
              }});

          choice1 = new Choice();
          choice1.add("Choice: popup ok");
          choice2 = new ChoiceNT();
          choice2.add("ChoiceNT: popup not ok JVM >= 1.4");
          String s;
          for (int i=1; i <= 5; i++) { // add a few more items
            s = Integer.toString(i);
            choice1.add(s);
            choice2.add(s);
          };
          keyButton = new Button("A-Z");
          keyButton.addActionListener(this);
          keyLetter = 'A';
          text1 = new KeyText("direct:");
          text2 = new KeyText("dispEv:");

          setLayout(new GridLayout(5,1));
          add(choice1);
          add(choice2);
          add(keyButton);
          add(text1);
          add(text2);
          pack();
          setVisible(true);
        }

        public void actionPerformed(ActionEvent ev) {
          if (ev.getSource() == keyButton) {
            // for text1, add 'key' directly
            text1.addChar(keyLetter);
            // for text2, add key via dispatchEvent
            text2.requestFocus(); // unnec for JVM < 1.4
            // even w/ requestFocus, some events still ignored/lost for >= JVM 1.4
            text2.dispatchEvent(new KeyEvent(this, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), KeyEvent.VK_SHIFT, keyLetter));
            keyLetter++;
            if (keyLetter > 'Z')
              keyLetter = 'A';
          }
        }
      }


      class ChoiceNT // for an app where another control uses Tab for internal navigation
        extends Choice
      {
        public boolean isFocusTraversable() { // refuse focus (via tab)
          return false;
        }
      }

      class KeyText
        extends Canvas
      {
        StringBuffer sb;
        static Font font = new Font("Monospaced", Font.PLAIN, 12);

        KeyText(String s) {
          addKeyListener(new KeyAdapter() {
            public void keyReleased(KeyEvent ev) {
              addChar(ev.getKeyChar());
            }});
          sb = new StringBuffer(s);
        }

        void addChar(char ch) {
          sb.append(ch);
          repaint();
        }

        public void paint(Graphics g) {
          g.setFont(font);
          g.drawString(sb.toString(), 0, 14);
        }

        public final Dimension getMinimumSize() {
          return new Dimension(200,16);
        }
        public final Dimension getPreferredSize() {
          return getMinimumSize();
        }
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I just use regular Choice class and tell my users that they can use only Enter (and not also Tab) key for navigation within my puzzle application.

      Release Regression From : 1.3.1
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-03-28 22:14:15 GMT

            dav Andrei Dmitriev (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: