Abstract table methods

Discussion in 'Java' started by AllyMilne, Jun 9, 2004.

  1. AllyMilne

    AllyMilne Guest

    The problem here has been causing me no end of grief. If anyone can
    figure out a solution then post it so other can be helped too. What
    im trying to do is get the setValueAt to addRow (an empty row) when
    the refence to setValueAt is greater than the number of table rows.

    Suffice to say it cannot resolve addRow

    ==============================================================
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;

    public class AbstractExample extends JFrame{

    public AbstractExample(){

    super("Abstract Model JTable Test");
    setSize(300,200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    TableModel tm=new AbstractTableModel(){

    String [][] data = {{" "," "," "," "," "," "}};
    String [] headers = { "Fetch", "
    Decode","Execut","Access","Writeback" };
    public int getRowCount() { return data.length;}
    public int getColumnCount() { return headers.length;}
    public Object getValueAt(int r, int c){ return data[r][c];}
    public String getColumnName(int c) {return headers[c];}
    //public void addRow(){ }
    public void setValueAt(Object o, int r, int c){
    int rowCount=getRowCount();
    if (r>rowCount)
    addRow();
    data[r][c]=(String)o;
    fireTableRowsUpdated(r,r);}
    };

    //Default colum model
    //need to make columns none movable


    JTable jt = new JTable(tm);

    JScrollPane jsp = new JScrollPane(jt);
    getContentPane().add(jsp, BorderLayout.CENTER);


    }

    public static void main (String args[]){
    AbstractExample ae= new AbstractExample();
    ae.setVisible(true);

    }
    }
    AllyMilne, Jun 9, 2004
    #1
    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. DaKoadMunky
    Replies:
    4
    Views:
    549
    Lee Weiner
    Apr 20, 2004
  2. Matthias Kaeppler
    Replies:
    1
    Views:
    436
    R.F. Pels
    May 22, 2005
  3. Sameer
    Replies:
    4
    Views:
    600
    Roedy Green
    Aug 31, 2005
  4. Iyer, Prasad C

    Abstract Methods & Abstract Class

    Iyer, Prasad C, Oct 20, 2005, in forum: Python
    Replies:
    0
    Views:
    532
    Iyer, Prasad C
    Oct 20, 2005
  5. Gerald Klix

    Re: Abstract Methods & Abstract Class

    Gerald Klix, Oct 20, 2005, in forum: Python
    Replies:
    1
    Views:
    343
    =?iso-8859-1?B?c+liYXN0aWVu?=
    Oct 20, 2005
Loading...

Share This Page