Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > DefaultTableModel

Reply
Thread Tools

DefaultTableModel

 
 
Cyril Dex
Guest
Posts: n/a
 
      09-20-2004
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!
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      09-20-2004
On 20 Sep 2004 03:33:32 -0700, Cyril Dex wrote:

> Hi all


Hi Cyril!

> I have a JTable


Good for you.. Do you have an example of this broken code?
<http://www.physci.org/codes/sscce.jsp>

> ...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.

<http://www.physci.org/codes/javafaq.jsp#stacktrace>

> 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
 
Reply With Quote
 
 
 
 
Nigel Wade
Guest
Posts: n/a
 
      09-21-2004
Cyril Dex wrote:

> 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) ?

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : http://www.velocityreviews.com/forums/(E-Mail Removed)
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
no method to remove all rows from DefaultTableModel Parvinder Java 2 06-15-2012 05:14 PM
extends DefaultTableModel ??? Peter Java 2 01-04-2005 12:04 PM
extends DefaultTableModel ? Peter Java 0 01-03-2005 06:27 AM
ArrayIndexOutOfBoundsException with DefaultTableModel Aloys Oberthuer Java 3 04-22-2004 04:32 PM
JTable - using DefaultTableModel - How do I make the table cells uneditable Deshaies Java 3 04-20-2004 04:00 PM



Advertisments