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

ItemListener not fired when using methods to select/deselect

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • None
    • 1.1
    • client-libs
    • None
    • sparc
    • solaris_2.5.1

    Description

      The ItemListener method itemStateChanged is not invoked when the state is changed via method calls. The listener is only notified when the user changes state via user gestures. The enclosed code will print out events when list items are selected by the mouse, but not when the "Next" button changes which item is selected.

      import java.awt.*;
      import java.awt.event.*;
       
      public class t extends java.applet.Applet
          implements ItemListener, ActionListener
      {
          private List list;
          private Button next = new Button("Next");
       
          public void init() {
              list = new List();
              for (int i = 0; i < 3; i++)
                  list.add(Integer.toString(i));
       
              list.addItemListener(this);
              next.addActionListener(this);
       
              add(list);
              add(next);
          }
       
          public void itemStateChanged(ItemEvent evt) {
              System.out.println("evt = " + evt);
          }
       
          public void actionPerformed(ActionEvent e) {
      System.out.println("next");
              int i = list.getSelectedIndex();
              ++i;
              i %= list.getItemCount();
              list.select(i);
          }
      }

      Attachments

        Issue Links

          Activity

            People

              msomlosunw Mike Somlo (Inactive)
              karnoldsunw Kenneth Arnold (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: