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