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

ListSelectionEvent called on a table even when moving a column which does not have a selection on it

    XMLWordPrintable

    Details

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

      Description

      I have a Jtable registered to a ListSelectionListener with row selection disabled and column selection enabled. I select the last column and then press F8 to set focus to header of first column. I next press Alt+Right Arrow key. The listener is being called even though the selection at the selected column has not changed in anyway.
      Steps to reproduce
      1)Execute the attached application.
      2)select the last column.(which has header named as Living)
      3)Press F8- focus appears on the first column header(First Name)
      4)Press Alt+Right Arrow.
      Expected
      Column moves, but no ListSelectionevent should be trigged.
      Actual
      Column moves, and ListSelectionevent is trigged.(Please look at the SOPs for this)
      I was able to reproduce this on mustang b71.
      I am adding the test case (SimpleTableDemo.java) here so the
      community on http://jdk.dev.java.net can see it:


      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import java.awt.Dimension;
      import java.awt.GridLayout;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.text.*;
      import javax.swing.table.*;
      import javax.swing.border.*;
      import javax.swing.colorchooser.*;
      import javax.swing.filechooser.*;
      import javax.accessibility.*;

      import java.awt.*;
      import java.awt.event.*;
      import java.awt.print.PrinterException;
      import java.beans.*;
      import java.util.*;
      import java.io.*;
      import java.applet.*;
      import java.net.*;

      import java.text.MessageFormat;
      import java.util.ArrayList;

      public class SimpleTableDemo extends JFrame implements ListSelectionListener {

          JTable table;
          public SimpleTableDemo() {

              javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
      createAndShowGUI();
      }
      });
          }


          private void createAndShowGUI() {
      setLayout(new GridLayout(1,0));

              String[] columnNames = {"First Name",
                                      "Last Name",
                                      "Address ",
                                      "Phone Number",
                                      "Living"
      };

              Object[][] data = {
      {"Rakesh", "Mood","AnPr", new Integer(1234), new Boolean(false)},
      {"Mahesh", "Sood","MaPr", new Integer(3456), new Boolean(false)},
      {"Quresh", "Food","UtPr", new Integer(4567), new Boolean(true)},
      {"Nocash", "Hood","HiPr", new Integer(5678), new Boolean(true)},
      {"Paresh", "Good","ArPr", new Integer(6789), new Boolean(false)}


              };

              JTable table = new JTable(data, columnNames);
              table.setColumnSelectionAllowed(true);
              table.setRowSelectionAllowed(false);
              table.setRowSorter(new TableRowSorter(table.getModel() ));
      table.getColumnModel().getSelectionModel().addListSelectionListener(this);
              JScrollPane scrollPane = new JScrollPane(table);

              add(scrollPane);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
              setSize(600,600);
              setVisible(true);
          }

          public static void main(String[] args) {
              SimpleTableDemo st = new SimpleTableDemo();

          }

          public void valueChanged(ListSelectionEvent l) {
      System.out.println("listSelectionevent.getFirstIndex()="+l.getFirstIndex());
      System.out.println("listSelectionevent.getLastIndex()="+l.getLastIndex());
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              peterz Peter Zhelezniakov
              Reporter:
              smandalisunw Srinivas Mandalika (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: