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

Tab key selects a non-existent row in an empty JTable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.1, 1.4.1
    • client-libs



      Name: jk109818 Date: 01/09/2003


      FULL PRODUCT VERSION :
      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)

      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 :

      windows 2000

      A DESCRIPTION OF THE PROBLEM :
      when you create JTable(model is default-empty), and
      use "tab" key to focus the table, you will select a row.
      I fount it in 1.3.1 and 1.4

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.create a new jtable
      2.use tab to focus talbe
      3.use method getSelectedRow to show the row u "selected"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      no row will be selected

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.ArrayIndexOutOfBoundsException: 0 >= 0

      at java.util.Vector.elementAt(Vector.java:417)

      at javax.swing.table.DefaultTableColumnModel.getColumn
      (DefaultTableColumnModel.java:276)

      at javax.swing.JTable.convertColumnIndexToModel(JTable.java:1623)

      at javax.swing.JTable.getValueAt(JTable.java:1714)

      at testproject.TestTableFrame.jButton1_actionPerformed
      (TestTableFrame.java:69)

      at testproject.TestTableFrame$1.actionPerformed
      (TestTableFrame.java:49)

      at javax.swing.AbstractButton.fireActionPerformed
      (AbstractButton.java:1450)

      at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed
      (AbstractButton.java:1504)

      at javax.swing.DefaultButtonModel.fireActionPerformed
      (DefaultButtonModel.java:378)

      at javax.swing.DefaultButtonModel.setPressed
      (DefaultButtonModel.java:250)

      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased
      (BasicButtonListener.java:216)

      at java.awt.Component.processMouseEvent(Component.java:3715)

      at java.awt.Component.processEvent(Component.java:3544)

      at java.awt.Container.processEvent(Container.java:1164)

      at java.awt.Component.dispatchEventImpl(Component.java:2593)

      at java.awt.Container.dispatchEventImpl(Container.java:1213)

      at java.awt.Component.dispatchEvent(Component.java:2497)

      at java.awt.LightweightDispatcher.retargetMouseEvent
      (Container.java:2451)

      at java.awt.LightweightDispatcher.processMouseEvent
      (Container.java:2216)

      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)

      at java.awt.Container.dispatchEventImpl(Container.java:1200)

      at java.awt.Window.dispatchEventImpl(Window.java:914)

      at java.awt.Component.dispatchEvent(Component.java:2497)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)

      at java.awt.EventDispatchThread.pumpOneEventForHierarchy
      (EventDispatchThread.java:131)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy
      (EventDispatchThread.java:98)

      at java.awt.EventDispatchThread.pumpEvents
      (EventDispatchThread.java:93)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)

      Selected row: 2



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package testproject;

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

      /**
       * <p>Title: </p>
       * <p>Description: </p>
       * <p>Copyright: Copyright (c) 2002</p>
       * <p>Company: </p>
       * @author richard xing
       * @version 1.0
       */

      public class TestTableFrame extends JFrame
      {
          private JScrollPane jScrollPane1 = new JScrollPane();
          private BorderLayout borderLayout1 = new BorderLayout();
          private JButton jButton1 = new JButton();
          private JTable jTable1 = new JTable();
          private JLabel jLabel1 = new JLabel();

          public TestTableFrame()
          {
              try
              {
                  jbInit();
              }
              catch(Exception e)
              {
                  e.printStackTrace();
              }
          }
          public static void main(String[] args)
          {
              TestTableFrame testTableFrame = new TestTableFrame();
              testTableFrame.setSize(640,480);
              testTableFrame.setVisible(true);
          }
          private void jbInit() throws Exception
          {
              this.getContentPane().setLayout(borderLayout1);
              jButton1.setText("Get Selected Row(Use \"TAB\" key focus table then
      click this button)");
              jButton1.addActionListener(new java.awt.event.ActionListener()
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      jButton1_actionPerformed(e);
                  }
              });
              jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
              jLabel1.setText("Test Table");
              this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
              jScrollPane1.getViewport().add(jTable1, null);
              this.getContentPane().add(jButton1, BorderLayout.SOUTH);
              this.getContentPane().add(jLabel1, BorderLayout.NORTH);
          }

          void jButton1_actionPerformed(ActionEvent e)
          {
              int[] rowNum = this.jTable1.getSelectedRows();

              try
                 {
                     for (int i = 0; i < rowNum.length; i++)
                     {
                         System.out.println("Selected row: "+rowNum[i]);
                         jTable1.getValueAt(rowNum[i],0);
                     }
                 }
                 catch (Exception ex)
                 {
                     ex.printStackTrace();
                  }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      when jtable tell u , it has selected some row , you should
      test the row in try-catch first. if it was correct, then
      continue , or ignore it . :)
      (Review ID: 178910)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: