Article View: borland.public.jbuilder.java.swing
Article #382Re: problem with jtable cell data
From: Jacques Chaurette
Date: Tue, 11 Oct 2005 02:17
Date: Tue, 11 Oct 2005 02:17
101 lines
3548 bytes
3548 bytes
Found the solution on the internet, it seems that the celLEditor is still
active and must be de-activated. AND IT WORKS
public void stopCellEditing() {
TableCellEditor editor = jTable1.getCellEditor();
if ( editor != null ) {
editor.stopCellEditing();
}
}
Cheers,
Jacques
"Jacques Chaurette" <jacques.chaurette@sympatico.ca> wrote in message
news:434acf22$1@newsgroups.borland.com...
>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:
<434b2032$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-in.ntli.net!newsrout1-win.ntli.net!newspeer1-win.ntli.net!news-out.ntli.net!newsrout1-gui.ntli.net!ntli.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<434acf22$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,9a7033b255ada9f8 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 References: <434acf22$1@newsgroups.borland.com> Subject: Re: problem with jtable cell data Date: Mon, 10 Oct 2005 22:17:40 -0400 Lines: 103 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; Response NNTP-Posting-Host: 70.49.62.10 Message-ID: <434b2032$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1128996914 70.49.62.10 (10 Oct 2005 19:15:14 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-in.ntli.net!newsrout1-win.ntli.net!newspeer1-win.ntli.net!news-out.ntli.net!newsrout1-gui.ntli.net!ntli.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail