exception when using two jtables in two different jdialog

From: anders (anders_at_no.spam)
Date: 05/26/04


Date: Wed, 26 May 2004 14:44:47 GMT

Hello,
I've a non modal dialog box displaying a jtable in my application. The
display works fine, I can change content of cells, add and remove rows
without any problem.

The table is created as followed:

Data is a vector of vectors
Columnnames is a vector

TableModel sharedModel = new CustomModel(data, columnnames);
JTable tp = new JTable(sharedModel);
JScrollPane sp = new JScrollPane(tp);

When I now select a jmenuitem from the user jmenu, a new jdialog, this
time modal, will be opened. This one too uses a jtable with complete
different content. Even here the display works fine, I can change
content of cells, add and remove rows without any problem.

String[] columnnames = new String[numCols];
Object[][] data = new Object[ncr][numCols];
TableModel sharedModel = new CustomModel(data,columnnames);
JTable tp = new JTable(sharedModel);
JScrollPane sp = new JScrollPane(tp);

i.e. both use the same CustomModel.
When I now close the modal box an exception occurs:

ava.lang.ArrayIndexOutOfBoundsException: 7 >= 6
       at java.util.Vector.elementAt(Vector.java:431)
       at
javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:277)
at javax.swing.JTable.convertColumnIndexToModel(JTable.java:1680)
at javax.swing.JTable.getValueAt(JTable.java:1771)
at alarmListCellRenderer2.getTableCellRendererComponent(Unknown Source)
at javax.swing.JTable.prepareRenderer(JTable.java:3731)

I don't really understand why, the two have nothing to do with each
other. If I use the second dialog without having the first on the screen
it works without an exception. I added an own implementation of
getColumn but it doesn't seem to be used, as I never get the output from
the System.out.println command (See below):

class CustomModel extends DefaultTableModel
{
       public CustomModel(Object[][] data, Object[] columnNames) {
               super(data, columnNames);
       }
       public CustomModel(Vector data, Vector columnNames) {
               super(data, columnNames);
       }
        public CustomModel(int rowCount, int columnCount) {
             super(rowCount, columnCount);
        }
 
        public Vector getColumn(int columnIndex) {
          System.out.println("CustomModel: get column "+columnIndex);
          if( columnIndex < dataVector.size() )
           return (Vector)dataVector.elementAt(columnIndex);
          else
          {
            Vector v = new Vector(1);
            v.set(0,"");
            return v;
          }
        }

       public Class getColumnClass(int col) {
               // dataVector is a protected member of DefaultTableModel
               
               Vector v = (Vector)dataVector.elementAt(0);
               return v.elementAt(col).getClass();
       }

       public boolean isCellEditable(int row, int col)
        {
               //Class columnClass = getColumnClass(col);
                boolean editable = true;

                String cn = gui.tp.getColumnName(col);
                if( cn.equals("ind") )
                  editable = false;
 

       return editable ; //columnClass != ImageIcon.class && columnClass
!= Date.class;
       }
}
//CustomModel



Relevant Pages

  • All words and Symbols of keybord should be added to Auto Shapes
    ... Suggestions are both for Word and Excel where applicable. ... Transpose should have an extra facility to transpose the selected cells ... display begins in the second line and therefore we cannot see row name A, B, ... And more in a single selection at a time, then there will be no problem. ...
    (microsoft.public.excel.misc)
  • Re: TMultiView, open-source flexible display component (alpha release)
    ... > or more cells, and the number of cells in each row can be different. ... > purpose is to display data that typically would be shown in a listview. ... Using a TMultiView you can allocate as much space as you ...
    (borland.public.delphi.thirdpartytools.general)
  • 26 Suggestions for both Word and Excel
    ... Transpose should have an extra facility to transpose the selected cells ... display begins in the second line and therefore we cannot see row name A, B, ... And more in a single selection at a time, then there will be no problem. ... Identity to any selected Paragraph, line, or any character or criteria. ...
    (microsoft.public.word.docmanagement)
  • Re: TMultiView, open-source flexible display component (alpha release)
    ... > or more cells, and the number of cells in each row can be different. ... > purpose is to display data that typically would be shown in a listview. ... Using a TMultiView you can allocate as much space as you ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Microcontroller help needed
    ... > cells, or equivalent batteries, then that would be great, if not... ... > -the display only needs to turn on for a minute after the switch is ... and the input connection could be taken to one of the ...
    (sci.electronics.design)