exception when using two jtables in two different jdialog
From: anders (anders_at_no.spam)
Date: 05/26/04
- Next message: eeyimaya: "Moving between JTextPanes with TAB key?"
- Previous message: ak: "Re: Question about JInternalFrame and MouseMotionListener"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: eeyimaya: "Moving between JTextPanes with TAB key?"
- Previous message: ak: "Re: Question about JInternalFrame and MouseMotionListener"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|