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

Inconsistent behavior on control-click in JTable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.2
    • client-libs
    • merlin
    • x86
    • windows_nt



      Name: skT88420 Date: 02/07/2000


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)

      /**
      Inconsistent behavior on control-click in JTable.

      In a JTable, when multiple interval selections are NOT allowed, the
      behavior on control-click is inconsistent. It alternates between
      two modes.

        To see an example, run this program. Select a cell. Then, hold down
      the control key and repeatedly click on any other cell IN THE SAME ROW
      OR COLUMN.

      Instead of getting the same behavior each time, the behavior
      alternates between two different modes. Sometimes the new cell will
      get an outline, then the next clicked-cell gets filled with the
      selection value. The next one gets the outline again.

      If the new cell doesn't share the same row or column, the behavior is
      consistent, in that the selection color fills the cell. This is what
      we should always see, regardless of where the click occured.

      Although the behavior differs slightly, the bug shows up when the
      selection mode is single-selection, or single-interval-selection.

      This bug shows up under JDK 1.2.2 and JDK 1.3 RC1.

      There is a similar RFE (4196969), but this strange behavior should be
      considered a bug.
      */

      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.table.*;

      class TableControlClick extends JTable implements ListSelectionListener
      {
        TableControlClick()
        {
          super();
          setModel(new TModel());
          setCellSelectionEnabled(true);
          
          // Choose one of these two lines:
          int sMode = ListSelectionModel.SINGLE_INTERVAL_SELECTION;
      // int sMode = ListSelectionModel.SINGLE_SELECTION;
          
          getSelectionModel().setSelectionMode(sMode);
          TableColumnModel cModel = getColumnModel();
          cModel.getSelectionModel().setSelectionMode(sMode);
        }
        
        public static void main(String args[])
        {
          TableControlClick tbl = new TableControlClick();
          JFrame test = new JFrame("Selection Bug");
          test.addWindowListener(new WindowAdapter()
            {
              public void windowClosing(WindowEvent evt)
              {
                System.exit(0);
              }
            }
          );
          test.getContentPane().add(new JScrollPane(tbl));
          test.pack();
          test.show();
        }
        
        private class TModel extends AbstractTableModel
        {
          public int getColumnCount() { return 8; }
          public int getRowCount() { return 20; }
          public Object getValueAt(int row, int col) { return "Row " + row + ", Col "
      + col; }
        }
      }
      (Review ID: 100928)
      ======================================================================

            pmilnesunw Philip Milne (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: