Article View: borland.public.jbuilder.java.swing
Article #380problem with jtable cell data
From: Jacques Chaurette
Date: Mon, 10 Oct 2005 20:31
Date: Mon, 10 Oct 2005 20:31
83 lines
2811 bytes
2811 bytes
I am having trouble getting reliable access to an individual cell content.
The code for my jtable is like this:
class MyTableModel extends AbstractTableModel {
private String[] columnNames = {"Dia. (in)",
"Instal. Cost",
};
private Object[][] data = {
{"3", "25"},
{"4", "35"},
{"5", "40"},
{"6", "45"},
{"8", "50"}
};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
//if (col < 2) {
//return false;
//} else {
return true;
//}
}
public void setValueAt(Object value, int row, int col) {
if (DEBUG) {
System.out.println("Setting value at " + row + "," + col
+ " to " + value
+ " (an instance of "
+ value.getClass() + ")");
}
data[row][col] = value;
fireTableCellUpdated(row, col);
if (DEBUG) {
System.out.println("New value of data:");
printDebugData();
}
}
private void printDebugData() {
int numRows = getRowCount();
int numCols = getColumnCount();
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + data[j]);
}
System.out.println();
}
System.out.println("--------------------------");
}
}
When I edit a cell value in the table GUI, the change is not effective until
another cell is selected. and I want to use this modified value somewhere
else in the program. I cannot count on the user selecting another cell. How
can I get the change to be instantly incorporated into the table model?
Any help appreciated.
Thanks.
Jacques
Technical Details
Message-ID:
<434acf22$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 111d45,9a7033b255ada9f8,start X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Jacques Chaurette" <jacques.chaurette@sympatico.ca> Newsgroups: borland.public.jbuilder.java.swing Subject: problem with jtable cell data Date: Mon, 10 Oct 2005 16:31:48 -0400 Lines: 85 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 70.49.62.10 Message-ID: <434acf22$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1128976162 70.49.62.10 (10 Oct 2005 13:29:22 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail