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

Selecting all rows in JTable using mouse is inconsistent

XMLWordPrintable

    • generic, x86
    • generic, windows_2000, windows_xp

      Name: jk109818 Date: 02/12/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

      FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000
      [Version 5.00.2195]


      ADDITIONAL OPERATING SYSTEMS :


      A DESCRIPTION OF THE PROBLEM :
      When you quickly drag select over all rows in a JTable not
      all rows are selected.

       
      We have users who want to be able to quickly select all
      rows using the mouse. (They are morally opposed to ctrl-A).
      This behavior is driving them nuts.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.Run SimpleTableDemo.java distributed with JDK 1.4.1
      2.Click on the first row in the table.
      3.Quickly drag select to the bottom finishing with the
      mouse well below the edge of the table.
      4. Not all rows are selected.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      I expect that all rows should be selected. In actuality
      not all rows are selected. If we repeat the above procedure
      *slowly* drag selecting, the result is that all rows are
      selected.

       We have a group of users that is going nuts over this.
      They need to be able to quickly select all rows with the
      mouse.


      SOURCE CODE:

      import javax.swing.JTable;
      import javax.swing.JScrollPane;
      import javax.swing.JPanel;
      import javax.swing.JFrame;
      import java.awt.*;
      import java.awt.event.*;

      public class SimpleTableDemo extends JFrame {
          private boolean DEBUG = true;

          public SimpleTableDemo() {
              super("SimpleTableDemo");

              Object[][] data = {
                  {"Mary", "Campione",
                   "Snowboarding", new Integer(5), new Boolean(false)},
                  {"Alison", "Huml",
                   "Rowing", new Integer(3), new Boolean(true)},
                  {"Kathy", "Walrath",
                   "Chasing toddlers", new Integer(2), new Boolean(false)},
                  {"Sharon", "Zakhour",
                   "Speed reading", new Integer(20), new Boolean(true)},
                  {"Angela", "Lih",
                   "Teaching high school", new Integer(4), new Boolean(false)}
              };

              String[] columnNames = {"First Name",
                                      "Last Name",
                                      "Sport",
                                      "# of Years",
                                      "Vegetarian"};

              final JTable table = new JTable(data, columnNames);
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));

              if (DEBUG) {
                  table.addMouseListener(new MouseAdapter() {
                      public void mouseClicked(MouseEvent e) {
                          printDebugData(table);
                      }
                  });
              }

              //Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);

              //Add the scroll pane to this window.
              getContentPane().add(scrollPane, BorderLayout.CENTER);

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

          private void printDebugData(JTable table) {
              int numRows = table.getRowCount();
              int numCols = table.getColumnCount();
              javax.swing.table.TableModel model = table.getModel();

              System.out.println("Value of data: ");
              for (int i=0; i < numRows; i++) {
                  System.out.print(" row " + i + ":");
                  for (int j=0; j < numCols; j++) {
                      System.out.print(" " + model.getValueAt(i, j));
                  }
                  System.out.println();
              }
              System.out.println("--------------------------");
          }

          public static void main(String[] args) {
              SimpleTableDemo frame = new SimpleTableDemo();
              frame.pack();
              frame.setVisible(true);
          }
      }





      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER WORKAROUND :
      slowly drag select all rows
      (Review ID: 180125)
      ======================================================================

            Unassigned Unassigned
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: