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

JListBox.getSelectedIndices() does not work correctly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 0.9
    • 1.1.2
    • client-libs
    • None
    • 0.9internal
    • generic
    • solaris_2.5.1
    • Verified

    Description

      To reproduce the problem, compile and run the following code.

      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;

      public class listbox2
      {
          public static void main(String[] args)
              {
                  String strings[] = { "zero", "one", "two", "three", "four" };
                  final JListBox listbox = new JListBox( strings );
                  JPanel p = new JPanel();
                  p.setLayout(new GridLayout(1,1));
                  p.add(listbox);

                  listbox.addSelectionInterval(0,3);
                  int ids[] = listbox.getSelectedIndices();
                  System.out.println( "Number of selected indices = " + ids.length +
                                      " (should be 4)" );
                  System.out.println( "Selected indices:" );
                  for( int i=0; i<ids.length; i++ )
                      System.out.println( " " + ids[i] );

                  WindowListener l = new WindowAdapter() {
                      public void windowClosing(WindowEvent e) {System.exit(0);}
                  };

                  JFrame f = new JFrame("ListBox");
                  f.addWindowListener(l);
                  f.add(p);
                  f.pack();
                  f.show();
              }
      }

      Attachments

        Activity

          People

            busersunw Btplusnull User (Inactive)
            tbarbaro Tracy Barbaro (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: