Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

can anybody please check this code out?

3 views
Skip to first unread message

Lorenzo

unread,
Jan 18, 2007, 5:50:38 AM1/18/07
to
Hi all,

I'm rather inexperienced in Java but I'm in need of defining a
JTable(N,N) with non-editable underdiagonal elements. I do not know if
it's better to do it by using TableModel or directly JTable, but I used
the latter because it looked easier to me.
The following code gives no errors in NetBeans, but using the newborne
UD_JTable class in MATLAB I get a very nasty error which pretty much
looks like some sort of memory allocation fault.


Here is the code:


import javax.swing.*;
import javax.swing.table.*;

public class UD_JTable extends JTable
{
public UD_JTable(int rows, int cols)
{
super();
}
public boolean isCellEditable( int rowIndex , int columnIndex)
{
if(rowIndex > columnIndex)
{
return false;
}
else
{
return true;
}
}

public static void main(String[] args)
{

}

}

And here is the error

??? Java exception occurred:
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0

at java.util.Vector.elementAt(Unknown Source)

at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source)

at javax.swing.JTable.convertColumnIndexToModel(Unknown Source)

at javax.swing.JTable.setValueAt(Unknown Source)
.

Does anybody have a clue of what's happening???

Thank you ahead


lor

Andrew Thompson

unread,
Jan 18, 2007, 5:59:51 AM1/18/07
to
Lorenzo wrote:
> Hi all,

Please X-post, rather than multi-post.

(X-post to c.l.j.p./h., w/ f-u to c.l.j.h. only)

Andrew T.

Daniel Röder

unread,
Jan 18, 2007, 6:05:32 AM1/18/07
to
Hi.

Lorenzo schrieb:


>
> public class UD_JTable extends JTable
> {
> public UD_JTable(int rows, int cols)
> {
> super();
> }

Maybe "super(rows, cols)" instead of "super()" will help.
With "super()" you call the non-arg Constructor of JTable, but I think
you want to call the Constructor, which takes two ints as the number of
the rows and cols.

<snip API-Doc>
JTable() - Constructs a default JTable that is initialized with a
default data model, a default column model, and a default selection model.
JTable(int numRows, int numColumns) - Constructs a JTable with numRows
and numColumns of empty cells using DefaultTableModel.
<snap>


Daniel Röder

Lorenzo

unread,
Jan 18, 2007, 6:10:09 AM1/18/07
to
WOW, that worked!!
thank you so much!

lor

0 new messages