DefaultTableModel

C

Cyril Dex

Hi all

I have a JTable which uses a customised DefaultTableModel called
TableModel. TableModel extends DefaultTableModel.

Now the ResultViewer.java class that I have is supposed to display the
names of files and their properties in 3 columns. The ResultViewer is
supposed to update after every 20 secs. The problem is that when an
update occurs, an ArrayIndexOutOfBoundsException occurs. I think that
the array references a null pointer in the vector when its updating.
The update occurs by 1st clearing the existing table then updating it.
I think when the update occrus here it references null. Its more of a
logical error.

public void clearTable () {
for (int row = (table.getRowCount() -1) ; row >= 0; row--) {
((DefaultTableModel) table.getModel()).removeRow(row);
}
}

I've already tried the fireTableRowsUpdated method and it doesn't seem
to work.

Thanks in advance.

Cheers!
 
A

Andrew Thompson


Hi Cyril!
I have a JTable

Good for you.. Do you have an example of this broken code?
...The problem is that when an
update occurs, an ArrayIndexOutOfBoundsException occurs. I think that
the array references a null pointer in the vector when its updating.

Stop guessing and find out.

<http://www.physci.org/codes/javafaq.jsp#exact>
Check especially the links to Exception explanations.

I think when the update occrus here it references null.

That should throw a NullPointerException, look these errors
up in the JavaDocs, and the links at the Java Glossary.
..Its more of a logical error.
...hmmm.

public void clearTable () {
for (int row = (table.getRowCount() -1) ; row >= 0; row--) {
((DefaultTableModel) table.getModel()).removeRow(row);
}
}

Yes, that tells me you have some lines of Java in your
files, now what does the stack trace say, does it refer
to one of those lines? Which one?
Thanks in advance.

And in future, it might pay to ask an actual question Cyril.

Your level of experience at Java and posting
suggests to me you might get better value from
a group further described here..
<http://www.physci.org/codes/javafaq.jsp#cljh>

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
N

Nigel Wade

Cyril said:
Hi all

I have a JTable which uses a customised DefaultTableModel called
TableModel. TableModel extends DefaultTableModel.

Dubious naming since there is a TableModel already in javax.swing.table.
Now the ResultViewer.java class that I have is supposed to display the
names of files and their properties in 3 columns. The ResultViewer is
supposed to update after every 20 secs. The problem is that when an
update occurs, an ArrayIndexOutOfBoundsException occurs. I think that
the array references a null pointer in the vector when its updating.
The update occurs by 1st clearing the existing table then updating it.
I think when the update occrus here it references null. Its more of a
logical error.

public void clearTable () {
for (int row = (table.getRowCount() -1) ; row >= 0; row--) {
((DefaultTableModel) table.getModel()).removeRow(row);
}
}

It's something in the code you are not showing us. If you run this code for
a JTable with a DefaultTableModel it doesn't throw any Exceptions.

BTW, what's wrong with DefaultTableModel.setRowCount(0) ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top