Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redisplay Jtable data vie fireTableDataChanged()???

Status
Not open for further replies.

sapatos

Programmer
Jan 20, 2006
57
AU
Hi,

I have a class BeanTableModel that provides a List of beans with fields for display in a jTable. I've gotten the initial list to display via netbeans using bind->elements and choosing the relevant list.

However following completion of some processing I need to be able to choose to display a different list of data on user request. I.e. processing complete do you want to see old data(already displayed) or new data (from new list).

I'm looking at the fireTableDataChanged() method with the addTableModelListener in the tablemodel. I just can't find any working examples to match my requirements. The table model class i have put together is below:

public class BeanTableModel extends AbstractTableModel implements TableModelListener {

String[] colNames = {"WorkSheet", "ApirCode", "LoadWarning", "PreRunWarn",
"FromExDate", "ToExDate", "Total", "CalcTotal", "DeltaBean"
};
private List<SpreadSheetRecord> beanList = Utility.getInstanceSSList();
private int i = 0;
Object[][] coldata = new Object[beanList.size()][colNames.length];

public BeanTableModel() {
for (SpreadSheetRecord s : beanList) {

coldata[0] = s.getWorkSheetName();
coldata[1] = s.getApirCode();
coldata[2] = s.getLoadWarning();
coldata[3] = s.getPrevRunWarning();
coldata[4] = s.getFromExDate();
coldata[5] = s.getToExDate();
coldata[6] = s.getTotal();
coldata[7] = s.getCalcTotal();
coldata[8] = s.getDeltaBean();
i++;
}

addTableModelListener(this);
}

public void getFireTableEvent () {
fireTableDataChanged();
}


public int getColumnCount() {
return colNames.length;
}

public int getRowCount() {
return coldata.length;
}

public String getColumnName(int col) {
return colNames[col];
}

public Object getValueAt(int row, int col) {
return coldata[row][col];
}

public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}

public boolean isCellEditable(int row, int col) {
return true;
}

public void setValueAt(Object value, int row, int col) {
coldata[row][col] = value;
fireTableDataChanged();
}

public void tableChanged(TableModelEvent e) {
coldata = null;

// throw new UnsupportedOperationException("Not supported yet.");
}
}

At the moment I've set the coldata to null in an attempt to remove data from the jTable to prove its calling it. In reality this would be pointing to another list.

Any ideas for URL's on good tutorials on this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top