Refresh data in JTable

hi, i hava a problem, i have a jtable where same Data column depend from another column of the same jtable and a jtextfield that is external to jtable

my jtable is

jcombobox | text | text | text ecc....

when the user change the SelectedItem of jcombobox the other column`s data is jacombobox values * external JtextField text....

if i change the value of the external jtextfield how can i refresh the data in the jtable whitout click over all cell?

this is the code of the My CellRender of the first column:

publicclass MyComboBoxRendererextends JComboBoximplements TableCellRenderer{

JTable jt;

PortataUgelli pug;

public MyComboBoxRenderer(String[] items,JTable table,PortataUgelli pu){

super(items);

this.jt=table;

this.pug=pu;

addItemListener(new java.awt.event.ItemListener(){

publicvoid itemStateChanged(java.awt.event.ItemEvent evt){

if (jt.getSelectedColumn()==0){//This action is only for the first column

String ugello= (String)getSelectedItem();

if (ugello==null) ugello=""+0;

double b=Double.parseDouble(pug.getPressione().trim());

String par="" +new VariID().getFunzioneUgelli(ugello,b);//this method calculate the value of the other cell

int sel;

if (jt.getSelectedRow() < 0) sel=0;

else sel = jt.getSelectedRow();

jt.setValueAt(par,sel,1);//set the value of the cell

}

}

});

}

public Component getTableCellRendererComponent(JTable table, Object value,

boolean isSelected,boolean hasFocus,int row,int column){

if (isSelected){

setForeground(table.getSelectionForeground());

super.setBackground(table.getSelectionBackground());

}else{

setForeground(table.getForeground());

setBackground(table.getBackground());

}

// Select the current value

setSelectedItem(value);

returnthis;

}

}

[3415 byte] By [middiua] at [2007-11-27 3:23:40]
# 1

It's fairly simple...

you need to have your own custom TableModel. Extend AbstractTableModel and when you go to set a cell (to change the data in that cell) you simply fire an event with the:

fireTableCellUpdated(int row, int column)

method to let the view know that the data changed in that cell of that table changed and needs to be redrawn...

Here's the link to the tutorial page/section on creating a custom table model and also firing events when data changes:

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#data

mr.v.a at 2007-7-12 8:26:27 > top of Java-index,Desktop,Core GUI APIs...
# 2
You don't change the data of a table in the renderer. I believe you should be using a TableModelListener. This posting has a simple example: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566133
camickra at 2007-7-12 8:26:27 > top of Java-index,Desktop,Core GUI APIs...