Board index » jbuilder » please tell me how to refresh the data of jtable

please tell me how to refresh the data of jtable


2004-05-03 09:48:10 AM
jbuilder19
I used a table model for a JTable, but don't know how to refresh it
I tried to change data in the model, but it doesn't refresh in JTable
Here is my table model, please help me.
import javax.swing.table.*;
public class TableModel extends AbstractTableModel {
private String[] header=null;
private Object[][] data=null;
public void setData (Object [][] Data) { data=Data;}
public void setHeader (String[] Header) {header=Header;}
public int getColumnCount() {
try {
return header.length;
} catch (Exception e) {
return 0;
}
}
public int getRowCount() {
try {
return data.length;
} catch (Exception e) {
return 0;
}
}
public Object getValueAt(int row, int col) {
try {
return data[row][col];
} catch (Exception e) {
return null;
}
}
public String getColumnName(int column) {
try {
return header[column];
} catch (Exception e) {
return null;
}
}
public boolean isCellEditable(int row, int col) { return (col==1); }
public void setValueAt(Object aValue, int row, int column) {
try {
data[row][column] = aValue;
} catch (Exception e) {}
}
}
 
 

Re:please tell me how to refresh the data of jtable

Hi Benny,
Have you looked at the fireTableXXXX() methods
Calling one of these as appropriate should help (fireTableDataChanged()
????????)
Arth
"Benny" < XXXX@XXXXX.COM >wrote in message
Quote
I used a table model for a JTable, but don't know how to refresh it
I tried to change data in the model, but it doesn't refresh in JTable
Here is my table model, please help me.

import javax.swing.table.*;

public class TableModel extends AbstractTableModel {

private String[] header=null;
private Object[][] data=null;

public void setData (Object [][] Data) { data=Data;}

public void setHeader (String[] Header) {header=Header;}

public int getColumnCount() {
try {
return header.length;
} catch (Exception e) {
return 0;
}
}

public int getRowCount() {
try {
return data.length;
} catch (Exception e) {
return 0;
}
}

public Object getValueAt(int row, int col) {
try {
return data[row][col];
} catch (Exception e) {
return null;
}
}

public String getColumnName(int column) {
try {
return header[column];
} catch (Exception e) {
return null;
}
}

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

public void setValueAt(Object aValue, int row, int column) {
try {
data[row][column] = aValue;
} catch (Exception e) {}
}
}

--
BT精神


 

Re:please tell me how to refresh the data of jtable

Meant to say, I found that if I updated the header to get that to display
you have to do something like
myTable.getTableHeader().updateUI();
Arth
 

{smallsort}

Re:please tell me how to refresh the data of jtable

thx a lot
"Arthur Ore" < XXXX@XXXXX.COM >撰寫於郵件新聞
: XXXX@XXXXX.COM ...
Quote
Meant to say, I found that if I updated the header to get that to display
you have to do something like

myTable.getTableHeader().updateUI();

Arth