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

BasicListUI.installKeyboardActions incorrectly implements keyboard actions

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description



      Name: nkR10003 Date: 10/16/2000


      JavaDoc comments for method BasicListUI.installKeyboardActions state:
      "... The actions just call out to protected methods, subclasses that
      want to override or extend keyboard behavior should consider
      just overriding those methods. This method is called at
      installUI() time.

      @see #selectPreviousIndex
      @see #selectNextIndex
      @see #installUI"

      Actually overriding of selectPreviousIndex() and selectNextIndex()
      methods has no effect.

      Example below demonstrates this problem:
      ------------------example--------------------
      import javax.swing.plaf.basic.*;
      import javax.swing.*;
      import java.awt.event.*;
      import java.awt.Window;

      class StubListUI extends BasicListUI {
          public StubListUI() {
              super();
          }
          
          protected void selectPreviousIndex() {
              System.out.println("select previous index");
              System.out.flush();
              super.selectPreviousIndex();
          }
          
          protected void selectNextIndex() {
              System.out.println("select next index");
              System.out.flush();
              super.selectPreviousIndex();
          }
      }

      public class test {
          public static void main(String[] args) {
              String[] data = {"one", "two", "three", "four", "five"};
              JList list = new JList(data);
              list.setSelectedIndex(0);
              StubListUI ui = new StubListUI();
              list.setUI(ui);
              JFrame frame = new JFrame("Test");
              frame.getContentPane().add(list);
              frame.setSize(100,
                      (int)list.getPreferredScrollableViewportSize().
                                                              getHeight());
              frame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      Window w = e.getWindow();
                      w.setVisible(false);
                      w.dispose();
                      System.out.println("Finish");
                      System.out.flush();
                      System.exit(0);
                  }
              });
              frame.setVisible(true);
          }
      }
      ----------------output:----------------------
      Finish
      ---------------------------------------------
      How to run the test:
          Compile and run example. Move the list selection with the arrow buttons.
          This actions should cause calls to selectPrevious(Next)Index methods
          and thus printing messages to System.out.
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              svioletsunw Scott Violet (Inactive)
              Reporter:
              knasunw Kna Kna (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: