Results 1 to 6 of 6
  1. #1
    agarta is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default JTable not updating with my AbstractTableModel

    I am new at programming and am working on my first school assignment. I have written a gui that accepts input and outputs data in a jtable added to a jpaddedpane. When the table first appears it shows all the correct data. But when I enter new input the table won´t update. I am alsmot positive the problem lies with my implementation of AstractTableModel. Can someone please take a look and correct it for me asap? Thanks in advance.

    ps. nh, vh, hNam, proc_1 and proc_ are integer, string, integer, string and string arrays respectively. They hold the data to be displayed in the table.

    Java Code:
    public class TableModel extends AbstractTableModel  {
            int numRows;
            String colNames[] = { "NH", "Horse Names", "VH",
                                  "Proc. I", "Proc. II" };        
            Object[][] obj;
    
            TableModel()  {
                super();
                numRows = fnh;
                obj = new Object[fnh][5];
    
                for( int i = 0; i < fnh; i++ )  {
                  for ( int j = 0; j < 5; j++ ) {
                      if ( j == 0 ) 
                          obj[i][0] = (Integer)nh[i];
                      else if ( j == 1 )
                          obj[i][1] = (String)hNam[i];
                      else if ( j == 2 )
                          obj[i][2] = (Integer)vh[i];
                      else if ( j == 3 )
                          obj[i][3] =(String)proc_1[i];
                      else 
                          obj[i][4] =(String)proc_2[i];        
                   }
               }
            }
    
            @Override
            public int getRowCount()  {
               return numRows;
            }
    
            @Override
            public int getColumnCount()  {
                return 5;
            }
    
            @Override
            public String getColumnName( int c ) {
                return colNames[c];
            }
    
            @Override
            public Object getValueAt( int r, int c )  {
                if ( c == 0 ) 
                    return nh[r];
                else if ( c == 1 )
                    return hNam[r];
                else if ( c == 2 )
                    return vh[r] ;
                else if ( c == 3 )
                    return proc_1[r];
                else
                    return proc_2[r];    
            }   
    
            @Override
            public boolean isCellEditable( int r, int c )  {
                return true;
            }        
    
            public void setValueAt( Object[][] value, int r, int c )  {
                   value = obj;
                   fireTableCellUpdated( r, c );
                 }            
    
            }    
        }
    Last edited by Fubarable; 03-31-2013 at 10:33 PM. Reason: quote tags changed to code tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default Re: JTable not updating with my AbstractTableModel

    The signature for your setValueAt( ... ) method is incorrect.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    agarta is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default Re: JTable not updating with my AbstractTableModel

    Sorry Jos, not following you

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default Re: JTable not updating with my AbstractTableModel

    Quote Originally Posted by agarta View Post
    Sorry Jos, not following you
    The first parameter of that method needs to be of type Object, not Object[][]; now it isn't even called (it's the empty method from the super class that is called).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,619
    Rep Power
    5

    Default Re: JTable not updating with my AbstractTableModel

    Ironically, the only one not monitored by an @Override annotation.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 3
    Last Post: 03-21-2012, 05:57 PM
  2. Updating JTable
    By dewitrydan in forum New To Java
    Replies: 3
    Last Post: 03-31-2011, 09:59 AM
  3. Updating the existing JTable !
    By Stephen Douglas in forum New To Java
    Replies: 2
    Last Post: 04-07-2010, 08:38 PM
  4. Problem with updating JTable
    By kwaspl in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 10:41 PM
  5. Updating database table from JTable
    By yesjava in forum New To Java
    Replies: 1
    Last Post: 08-16-2008, 10:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •