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

JTable doesn't cope well with emtyp table.

XMLWordPrintable

    • 1.0.2
    • sparc
    • solaris_2.5

      Swing-pre-1.0, jdk1.1.5.

      JTable throws exception : "java.lang.ArrayIndexOutOfBoundsException" when the table is empty.

      See below for a program desmontrating this bug.

      Removing the comments "//" at the beginning of the line "//
      rows.addElement(row);" solves the problem as the table is not anymore
      empty.


      /**
      * @(#)TestTable.java 98/01/12
      *
      * @version 1.2
      */
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;

      import com.sun.java.swing.*;
      import com.sun.java.swing.table.*;

      public class TestTable {
       JFrame TestFrame;

       private static final int WIDTH=500;
       private static final int HEIGHT=300;

       private JPanel TestPanel;
       private JTable TestTable;
       private Vector rows;
       private Vector columns;
       private DefaultTableModel table_model;

          /**
       * Class Constructor.
       */
          public TestTable() {

        TestFrame=new JFrame();

        TestFrame.setTitle("Test Table");
        createUI();
       }


          /**
       * Create user interface components.
       */
          public void createUI() {
        JPanel jp, jp1, jp2;
        String value;
        Vector row;

        TestPanel = new JPanel();
        TestPanel.setLayout(new BorderLayout());
        rows=new Vector();
        row=new Vector();
        row.addElement("1");
        row.addElement("2");
        row.addElement("3");
        // rows.addElement(row);
        columns=new Vector();
        columns.addElement("A");
        columns.addElement("B");
        columns.addElement("C");

        table_model=new DefaultTableModel(rows, columns);

        TestTable=new JTable(table_model);
        TestTable.setAutoCreateColumnsFromModel(false);
        TestTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        TestTable.setColumnSelectionAllowed(false);
               TestTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

        TestPanel.add(JTable.createScrollPaneForTable(TestTable),
      BorderLayout.CENTER);

        TestFrame.getContentPane().add(TestPanel);
        TestFrame.setResizable(true);
        TestFrame.setSize(new Dimension(WIDTH, HEIGHT));
        TestFrame.setVisible(true);
          }


          public static void main (String args[]) {
        TestTable f=new TestTable();
       }
      }

            erapinsunw Eric Rapin (Inactive)
            pchusunw Patience Chu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: