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

JMenu removeAccessibleSelection operates on wrong menu level

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      When addAccessibleSelection(0) is called on the first menu item, it correctly selects that item and expands the entire menu path. However, removeAccessibleSelection(0) does not remove the selection of the same first menu item. Instead, it truncates the last two elements of the selection path, leaving intermediate menu states active.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No Exception

      ---------- BEGIN SOURCE ----------
      import javax.accessibility.AccessibleSelection;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;

      public class JMenuTest {

          public static void main(String[] argv) {

              JMenuBar mb = new JMenuBar();
              JMenu mnu = new JMenu();
              AccessibleSelection acs = mnu.getAccessibleContext().getAccessibleSelection();
              mb.add(mnu);
              JMenu jm = new JMenu();
              mnu.add(jm);

              int initialCount = acs.getAccessibleSelectionCount();
              if (initialCount != 0) {
                  throw new RuntimeException(
                      "Initial selection count should be 0, got " + initialCount
                  );
              }

              acs.addAccessibleSelection(0);
              int afterAddCount = acs.getAccessibleSelectionCount();
              if (afterAddCount != 1) {
                  throw new RuntimeException(
                      "After adding selection, count should be 1, got " + afterAddCount
                  );
              }

              acs.removeAccessibleSelection(0);
              int afterRemoveCount = acs.getAccessibleSelectionCount();
              if (afterRemoveCount != 0) {
                  throw new RuntimeException(
                      "After removing selection, count should be 0, got " + afterRemoveCount
                  );
              }
          }

      }

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

            abhiscxk Abhishek Kumar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: