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

ListSelectionEvent can have indexes less than 0

    Details

    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      J2SE Version (please include all output from java -version flag):
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b96)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b96, mixed mode, sharing)

      Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
      Yes

      Operating System Configuration Information (be specific):
      Microsoft Windows 2000 [Version 5.00.2195]

      ListSelectionEvent can have indexes less than 0

      1) Run the code below
      2) Select a row in the table
      3) Press the button
      4) Observe in the console that the ListSelectionEvent have firstIndex = -1

      According to the ListSelectionEvent JavaDoc the indexes should represent the range of rows where the selection might have changed, where 0 is the first row. It should note that the firstIndex can be less than 0.

      import static java.awt.BorderLayout.*;
      import static java.lang.System.*;
      import static javax.swing.JFrame.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.table.*;

      public class Test {
        public static void main(String[] args) {
          JFrame frame = new JFrame();
          final JTable table = new JTable(3, 3) {
            public void valueChanged(ListSelectionEvent anEvent) {
              out.println(anEvent);
              super.valueChanged(anEvent);
            }
          };
          frame.add(new JScrollPane(table));
          frame.add(new JButton(new AbstractAction("Fire Table Data Changed") {
            public void actionPerformed(ActionEvent anEvent) {
              ((DefaultTableModel)table.getModel()).fireTableDataChanged();
            }
          }), SOUTH);
          frame.pack();
          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
          frame.setVisible(true);
        }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                serb Sergey Bylokhov
                Reporter:
                tyao Ting-Yun Ingrid Yao (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Imported:
                  Indexed: