DefaultTableModel

Discussion in 'Java' started by Cyril Dex, Sep 20, 2004.

  1. Cyril Dex

    Cyril Dex Guest

    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!
     
    Cyril Dex, Sep 20, 2004
    #1
    1. Advertising

  2. 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
     
    Andrew Thompson, Sep 20, 2004
    #2
    1. Advertising

  3. Cyril Dex

    Nigel Wade Guest

    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 :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
     
    Nigel Wade, Sep 21, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aloys Oberthuer
    Replies:
    3
    Views:
    7,673
    Aloys Oberthuer
    Apr 22, 2004
  2. Deshaies
    Replies:
    3
    Views:
    4,613
    Deshaies
    Apr 20, 2004
  3. Parvinder
    Replies:
    2
    Views:
    7,093
    PuneetNanda9
    Jun 15, 2012
  4. Peter
    Replies:
    2
    Views:
    3,085
    Andrew Thompson
    Jan 4, 2005
  5. Peter

    extends DefaultTableModel ?

    Peter, Jan 3, 2005, in forum: Java
    Replies:
    0
    Views:
    699
    Peter
    Jan 3, 2005
Loading...

Share This Page