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

AccessibleJTable.setAccessibleSelction should select rows/cols when cell selecti

XMLWordPrintable

    • tiger
    • generic
    • generic, solaris_9



      Name: yyT116575 Date: 08/22/2001

       
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


      Currently addAccessibleSelection does nothing if getCellSelectionEnabled() is
      false. The code is,

      public void addAccessibleSelection(int i) {
      if (JTable.this.cellSelectionEnabled) {
      int column = getAccessibleColumnAtIndex(i);
      int row = getAccessibleRowAtIndex(i);
      JTable.this.addRowSelectionInterval(row, row);
      JTable.this.addColumnSelectionInterval(column, column);
      }
      }

      When cell selection is not enabled therefore there is no way, using
      accessibility, to select rows or columns. It seems logical that selecting a cell
      using accessibility should have the same effect as clicking on a cell with the
      mouse. That is, if row or column selection is enabled, then selecting a cell
      should instead cause the row or column to be selected.

      The easy fix is to remove the if statement. A better solution would be,

      public void addAccessibleSelection(int i) {
      int column = getAccessibleColumnAtIndex(i);
      int row = getAccessibleRowAtIndex(i);
      JTable.this.changeSelection(row, column, true, false);
      }

      This way Accessibility would be using the same method as the table's UI.

      If nothing is done about this then there is no way through the Accessibility
      API to select anything in a JTable when cellSelectionEnabled is not true. It is
      possible that if the current implementation is deemed to be correct, then new
      methods could be added to the AccessibleTable interface to deal with this.

      Here's some sample code. The program creates a table, sets cell selection true,
      waits 2 seconds, calls addAccessibleSelection (this works), sets cell selection
      false and row selection true, waits 2 seconds, calls addAccessibleSelection
      (this fails and the row is not selected).

      import java.awt.Dimension;
      import java.awt.BorderLayout;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.accessibility.*;

      public class junk5 extends JFrame {
        public junk5() {

          setDefaultCloseOperation(EXIT_ON_CLOSE);

          Object[][] a = {{"this", new Integer(1)}, {"that", new Integer(2)},
              {"there", new Integer(3)}};
          Object[] c = {"Column one", "Column two"};

          JTable table = new JTable(a, c) {
            public void addRowSelectionInterval(int index0, int index1) {
              System.out.println("addRowSelectionInterval:" + index0 + " " + index1);
              super.addRowSelectionInterval(index0, index1);
            }
            public void addColumnSelectionInterval(int index0, int index1) {
              System.out.println("addColumnSelectionInterval:" + index0 + " " + index1);
              super.addColumnSelectionInterval(index0, index1);
            }
          };
          table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          table.setRowSelectionAllowed(false);
          table.setColumnSelectionAllowed(false);
          table.setCellSelectionEnabled(true);

          getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);

          setSize(200, 200);
          setVisible(true);
          pack();

          try {
            Thread.currentThread().sleep(2000);
          } catch(InterruptedException e) {
          }

          AccessibleContext ac = table.getAccessibleContext();
          AccessibleSelection as = ac.getAccessibleSelection();

          table.requestFocus();
          as.addAccessibleSelection(1);

          try {
            Thread.currentThread().sleep(2000);
          } catch(InterruptedException e) {
          }

          table.setCellSelectionEnabled(false);
          table.setColumnSelectionAllowed(false);
          table.setRowSelectionAllowed(true);

          table.requestFocus();
          as.addAccessibleSelection(3);

          System.out.println("Done.");

        }

        public Dimension getPreferredSize() {
          return new Dimension(200, 200);
        }

        public static void main (String[] argv) {
          junk5 j = new junk5();
        }
      }
      (Review ID: 130496)
      ======================================================================

            lmonsantsunw Lynn Monsanto (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: