Abstract table methods

A

AllyMilne

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

}
}
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top